Allow bitmap scans to operate as index-only scans when possible.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 1 Nov 2017 21:38:12 +0000 (17:38 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 1 Nov 2017 21:38:20 +0000 (17:38 -0400)
commit7c70996ebf0949b142a99c9445061c3c83ce62b3
treea7c65e4d32b27707fa8f4dd0f14b97a97feea282
parentec7ce54204147ccf1a55aaba526ac4b39071f712
Allow bitmap scans to operate as index-only scans when possible.

If we don't have to return any columns from heap tuples, and there's
no need to recheck qual conditions, and the heap page is all-visible,
then we can skip fetching the heap page altogether.

Skip prefetching pages too, when possible, on the assumption that the
recheck flag will remain the same from one page to the next.  While that
assumption is hardly bulletproof, it seems like a good bet most of the
time, and better than prefetching pages we don't need.

This commit installs the executor infrastructure, but doesn't change
any planner cost estimates, thus possibly causing bitmap scans to
not be chosen in cases where this change renders them the best choice.
I (tgl) am not entirely convinced that we need to account for this
behavior in the planner, because I think typically the bitmap scan would
get chosen anyway if it's the best bet.  In any case the submitted patch
took way too many shortcuts, resulting in too many clearly-bad choices,
to be committable.

Alexander Kuzmenkov, reviewed by Alexey Chernyshov, and whacked around
rather heavily by me.

Discussion: https://postgr.es/m/239a8955-c0fc-f506-026d-c837e86c827b@postgrespro.ru
src/backend/executor/nodeBitmapHeapscan.c
src/backend/optimizer/plan/createplan.c
src/include/nodes/execnodes.h
src/test/regress/expected/stats.out
src/test/regress/sql/stats.sql