Support index-only scans using the visibility map to avoid heap fetches.

Tom Lane <tgl@sss.pgh.pa.us>

Commit: a2822fb9337a21f98ac4ce850bb4145acf47ca27
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: 2011-10-08T00:14:13Z
Releases: 9.2.0
Support index-only scans using the visibility map to avoid heap fetches.

When a btree index contains all columns required by the query, and the
visibility map shows that all tuples on a target heap page are
visible-to-all, we don't need to fetch that heap page.  This patch depends
on the previous patches that made the visibility map reliable.

There's a fair amount left to do here, notably trying to figure out a less
chintzy way of estimating the cost of an index-only scan, but the core
functionality seems ready to commit.

Robert Haas and Ibrar Ahmed, with some previous work by Heikki Linnakangas.

Files

PathChange+/−
doc/src/sgml/catalogs.sgml modified +7 −0
doc/src/sgml/config.sgml modified +18 −1
doc/src/sgml/indexam.sgml modified +31 −1
doc/src/sgml/ref/postgres-ref.sgml modified +5 −2
src/backend/access/index/genam.c modified +4 −0
src/backend/access/index/indexam.c modified +150 −86
src/backend/access/nbtree/nbtree.c modified +92 −0
src/backend/commands/explain.c modified +4 −1
src/backend/executor/nodeIndexscan.c modified +114 −9
src/backend/nodes/copyfuncs.c modified +1 −0
src/backend/nodes/outfuncs.c modified +2 −0
src/backend/optimizer/path/costsize.c modified +21 −0
src/backend/optimizer/path/indxpath.c modified +89 −0
src/backend/optimizer/plan/createplan.c modified +6 −3
src/backend/optimizer/plan/planner.c modified +1 −1
src/backend/optimizer/util/pathnode.c modified +6 −2
src/backend/optimizer/util/plancat.c modified +1 −0
src/backend/optimizer/util/var.c modified +29 −14
src/backend/tcop/postgres.c modified +4 −1
src/backend/utils/cache/relcache.c modified +2 −2
src/backend/utils/misc/guc.c modified +9 −0
src/backend/utils/misc/postgresql.conf.sample modified +1 −0
src/include/access/genam.h modified +3 −0
src/include/access/relscan.h modified +5 −0
src/include/catalog/catversion.h modified +1 −1
src/include/catalog/pg_am.h modified +27 −25
src/include/nodes/execnodes.h modified +2 −0
src/include/nodes/plannodes.h modified +5 −0
src/include/nodes/relation.h modified +6 −0
src/include/optimizer/cost.h modified +3 −1
src/include/optimizer/pathnode.h modified +1 −0
src/include/optimizer/var.h modified +1 −1
src/test/regress/expected/aggregates.out modified +39 −39
src/test/regress/expected/rangefuncs.out modified +14 −13