Re: index-only count(*) for indexes supporting bitmap scans

From: Alexander Kuzmenkov <a(dot)kuzmenkov(at)postgrespro(dot)ru>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: index-only count(*) for indexes supporting bitmap scans
Date: 2017-04-12 17:10:36
Message-ID: 2b547a5d-83ad-5d9d-923e-4b39b8bf0fe1@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 12.04.2017 17:24, Tom Lane wrote:
> TBH, I'm not sure you need to do any of that work. Have you got evidence
> that the planner will fail to choose the right plan regardless? I'm
> particularly unconvinced that choose_bitmap_and is a critical problem,
> because once you're into having to AND multiple indexes, you're talking
> about an expensive query anyhow.
The most expensive part would probably be accessing the heap in the
bitmap heap scan. It may be worth trying to choose an index path that
checks all the restriction and therefore allows us to skip this heap
access. This path might not be the cheapest one, though. The standard
AND selection procedure would have discarded it based on cost.
I've seen this happen on the regression database. Somehow I can't seem
to reproduce it on my earlier full-text search example.

An example:

regression=# explain select count(*) from tenk1 where hundred < 90 and
thousand < 31;
QUERY PLAN
-------------------------------------------------------------------------------------------
Bitmap Count on tenk1 (cost=182.69..185.56 rows=1 width=8)
Recheck Cond: ((thousand < 31) AND (hundred < 90))
-> BitmapAnd (cost=182.69..182.69 rows=287 width=0)
-> Bitmap Index Scan on tenk1_thous_tenthous (cost=0.00..6.68
rows=319 width=0)
Index Cond: (thousand < 31)
-> Bitmap Index Scan on tenk1_hundred (cost=0.00..175.62
rows=8978 width=0)
Index Cond: (hundred < 90)
(7 rows)

regression=# set enable_bitmapcount to off;
SET
regression=# explain select count(*) from tenk1 where hundred < 90 and
thousand < 31;
QUERY PLAN
-------------------------------------------------------------------------------------------
Aggregate (cost=375.34..375.35 rows=1 width=8)
-> Bitmap Heap Scan on tenk1 (cost=6.75..374.62 rows=287 width=0)
Recheck Cond: (thousand < 31)
Filter: (hundred < 90)
-> Bitmap Index Scan on tenk1_thous_tenthous (cost=0.00..6.68
rows=319 width=0)
Index Cond: (thousand < 31)
(6 rows)

--

Alexander Kuzmenkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2017-04-12 17:11:46 Re: Some thoughts about SCRAM implementation
Previous Message Tom Lane 2017-04-12 17:00:37 Re: [sqlsmith] ERROR: badly formatted node string "RESTRICTINFO...