Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdzxe-0001x6-3j for pgsql-performance@arkaria.postgresql.org; Thu, 20 Jun 2019 16:30:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hdzxc-0003bD-3s for pgsql-performance@arkaria.postgresql.org; Thu, 20 Jun 2019 16:30:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdzxb-0003XR-LB for pgsql-performance@lists.postgresql.org; Thu, 20 Jun 2019 16:30:51 +0000 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdzxY-0000Ww-HW for pgsql-performance@postgresql.org; Thu, 20 Jun 2019 16:30:51 +0000 Received: by mail-io1-xd41.google.com with SMTP id e3so1307040ioc.12 for ; Thu, 20 Jun 2019 09:30:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=+QIWfwf9Sf+LzzzeLas+zXM+hGIGXg/kJVp2LYlZMLg=; b=OaG4SMBeQDIHI3pOV7MI+gco+IO8HtuL10nUK5zjyePqHr3zexCeqFIKPDyheW0pui FIBPm+pw6BizT+1TIIZD9laF41noYqX4K+KI9rfPke9K3t/Zegso+fnmIhcacPIDxheM +j7oyoYhmpx1RldHa4ExR0OqZKFb67QplAtPjCDEuKmdN293tp8AUni9L9VqCEnY+D0v 9k7mzniqLgqaFpbUILmaT+1n+hCEMssqlUOiXTqEmiyEv/UiqOhOq55uYJI1Nod82eY9 vuSfr4U15VjcUFykyI3+eeDgKqU157jZLYIvfOR5SG0HOBn1idvHExnlSJDhN7WFMNA5 MHXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=+QIWfwf9Sf+LzzzeLas+zXM+hGIGXg/kJVp2LYlZMLg=; b=f4mc+phweSsjwK77M7nyw1TvRSgPpwHB0Q+xEsw9ACIZewbX9D9dbXYzjxWec85Hs/ FHpN7jC+/tH9+Myz9GaG2W7N2xH+xIqh/wETx/CDw0VzG//Pm+XLshoStN36CIYegkSz shAVe1jFhazjIAq5ajOa8XgAUO11WIrBr1rw1doMchNZp1+S4a+ymovkjzhO78uKQHJt x5bg7PDiIN8kshvjZ9VXlUogL+IKwNsb0BehgzvgVE1KbVdl3UbDb9ot87VBTZ1tSEZ3 taSKVoPn1VusjUNFqwk5QYhmalHLe826qttKD8cwgBfcsdoJEW3bjIXUESRejy0UEGWQ Y0Bg== X-Gm-Message-State: APjAAAXxCLFP9BDvIEOv7/DV8ABA+Pz6QUz2Bk1GDvE0iK+BbkKCb+V8 c0/pYVVeGqhuJ6ZBLSmFXvnQaA== X-Google-Smtp-Source: APXvYqwCVRZDiczkhy00sb2muKElSV+U4A/lZSNIeuDMJTu5Ve/q552cU+HKTZ0Ji4nbIjqYuitKoA== X-Received: by 2002:a5e:db0a:: with SMTP id q10mr9577657iop.168.1561048246303; Thu, 20 Jun 2019 09:30:46 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id l11sm366467ioj.32.2019.06.20.09.30.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2019 09:30:45 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 8B846800CF1; Thu, 20 Jun 2019 11:30:44 -0500 (CDT) Date: Thu, 20 Jun 2019 11:30:44 -0500 From: Justin Pryzby To: Simon Riggs Cc: Chris Wilson , "pgsql-performance@postgresql.org" Subject: Re: EXPLAIN ANALYZE of BRIN bitmap index scan with disjunction Message-ID: <20190620163044.GU16019@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Jun 20, 2019 at 05:18:33PM +0100, Simon Riggs wrote: > On Thu, 20 Jun 2019 at 17:01, Chris Wilson > wrote: > > > > I deliberately included r in the index, to demonstrate the issue that I’m > > seeing. I know that there is very little locality in this particular, > > dummy, arbitrary test case. I can try to produce a test case that has some > > locality, but I expect it to show exactly the same results, i.e. that the > > BRIN index performs much worse when we try to query on this column as well. > > > > I'm suggesting that adding the second column to the index is the source of > your problem, not adding the column to the query. But it *is* odd that the index returns more rows with a strictly tighter conditions, right ? Note, it's not an issue of rowcount estimate being confused by redundant conditions, but real rowcount, and it returns more rows even when the conditions are duplicative. Compare: postgres=# explain analyze select * from brin_test where id >= 90000 and r in (1); ... -> Bitmap Index Scan on brin_test_id_r_idx (cost=0.00..12.03 rows=28125 width=0) (actual time=0.136..0.137 rows=37120 loops=1) Index Cond: ((id >= 90000) AND (r = 1)) postgres=# explain analyze select * from brin_test where id >= 90000 and r in (1,1); ... -> Bitmap Index Scan on brin_test_id_r_idx (cost=0.00..12.03 rows=28125 width=0) (actual time=0.263..0.263 rows=74240 loops=1) Index Cond: ((id >= 90000) AND (r = ANY ('{1,1}'::integer[]))) postgres=# explain analyze select * from brin_test where id >= 90000 and r in (1,1,1); ... -> Bitmap Index Scan on brin_test_id_r_idx (cost=0.00..12.03 rows=28125 width=0) (actual time=0.387..0.387 rows=111360 loops=1) Index Cond: ((id >= 90000) AND (r = ANY ('{1,1,1}'::integer[]))) Note, the docs say: https://www.postgresql.org/docs/devel/indexes-multicolumn.html |A multicolumn BRIN index can be used with query conditions that involve any |subset of the index's columns. Like GIN and unlike B-tree or GiST, index search |effectiveness is the same regardless of which index column(s) the query |conditions use. The only reason to have multiple BRIN indexes instead of one |multicolumn BRIN index on a single table is to have a different pages_per_range |storage parameter. Justin