Indexes with INCLUDE columns and their support in B-tree

Teodor Sigaev <teodor@sigaev.ru>

Commit: 8224de4f42ccf98e08db07b43d52fed72f962ebb
Author: Teodor Sigaev <teodor@sigaev.ru>
Date: 2018-04-07T20:00:39Z
Releases: 11.0
Indexes with INCLUDE columns and their support in B-tree

This patch introduces INCLUDE clause to index definition.  This clause
specifies a list of columns which will be included as a non-key part in
the index.  The INCLUDE columns exist solely to allow more queries to
benefit from index-only scans.  Also, such columns don't need to have
appropriate operator classes.  Expressions are not supported as INCLUDE
columns since they cannot be used in index-only scans.

Index access methods supporting INCLUDE are indicated by amcaninclude flag
in IndexAmRoutine.  For now, only B-tree indexes support INCLUDE clause.

In B-tree indexes INCLUDE columns are truncated from pivot index tuples
(tuples located in non-leaf pages and high keys).  Therefore, B-tree indexes
now might have variable number of attributes.  This patch also provides
generic facility to support that: pivot tuples contain number of their
attributes in t_tid.ip_posid.  Free 13th bit of t_info is used for indicating
that.  This facility will simplify further support of index suffix truncation.
The changes of above are backward-compatible, pg_upgrade doesn't need special
handling of B-tree indexes for that.

Bump catalog version

Author: Anastasia Lubennikova with contribition by Alexander Korotkov and me
Reviewed by: Peter Geoghegan, Tomas Vondra, Antonin Houska, Jeff Janes,
			 David Rowley, Alexander Korotkov
Discussion: https://www.postgresql.org/message-id/flat/56168952.4010101@postgrespro.ru

Files

PathChange+/−
contrib/amcheck/expected/check_btree.out modified +46 −0
contrib/amcheck/sql/check_btree.sql modified +19 −0
contrib/amcheck/verify_nbtree.c modified +82 −16
contrib/bloom/blutils.c modified +1 −0
contrib/dblink/dblink.c modified +13 −13
contrib/dblink/expected/dblink.out modified +55 −0
contrib/dblink/sql/dblink.sql modified +38 −0
contrib/tcn/tcn.c modified +3 −3
doc/src/sgml/btree.sgml modified +17 −0
doc/src/sgml/catalogs.sgml modified +10 −2
doc/src/sgml/indexam.sgml modified +4 −1
doc/src/sgml/indices.sgml modified +5 −2
doc/src/sgml/ref/create_index.sgml modified +61 −1
doc/src/sgml/ref/create_table.sgml modified +29 −4
src/backend/access/brin/brin.c modified +1 −0
src/backend/access/common/indextuple.c modified +31 −0
src/backend/access/gin/ginutil.c modified +1 −0
src/backend/access/gist/gist.c modified +1 −0
src/backend/access/hash/hash.c modified +1 −0
src/backend/access/heap/heapam.c modified +1 −3
src/backend/access/index/genam.c modified +11 −8
src/backend/access/nbtree/nbtinsert.c modified +84 −35
src/backend/access/nbtree/nbtpage.c modified +12 −11
src/backend/access/nbtree/nbtree.c modified +1 −0
src/backend/access/nbtree/nbtsearch.c modified +60 −3
src/backend/access/nbtree/nbtsort.c modified +47 −5
src/backend/access/nbtree/nbtutils.c modified +46 −8
src/backend/access/nbtree/nbtxlog.c modified +22 −12
src/backend/access/nbtree/README modified +17 −0
src/backend/access/rmgrdesc/nbtdesc.c modified +8 −0
src/backend/access/spgist/spgutils.c modified +1 −0
src/backend/bootstrap/bootparse.y modified +2 −0
src/backend/bootstrap/bootstrap.c modified +1 −1
src/backend/catalog/heap.c modified +2 −1
src/backend/catalog/index.c modified +52 −34
src/backend/catalog/indexing.c modified +1 −0
src/backend/catalog/pg_constraint.c modified +25 −2
src/backend/catalog/toasting.c modified +1 −0
src/backend/commands/indexcmds.c modified +52 −11
src/backend/commands/matview.c modified +3 −3
src/backend/commands/tablecmds.c modified +5 −4
src/backend/commands/trigger.c modified +1 −0
src/backend/commands/typecmds.c modified +1 −0
src/backend/executor/execIndexing.c modified +7 −7
src/backend/executor/execReplication.c modified +3 −3
src/backend/executor/nodeIndexscan.c modified +5 −3
src/backend/nodes/copyfuncs.c modified +2 −0
src/backend/nodes/equalfuncs.c modified +2 −0
src/backend/nodes/outfuncs.c modified +4 −0
src/backend/optimizer/path/indxpath.c modified +1 −1
src/backend/optimizer/path/pathkeys.c modified +11 −2
src/backend/optimizer/README modified +6 −4
src/backend/optimizer/util/plancat.c modified +20 −13
src/backend/parser/analyze.c modified +3 −3
src/backend/parser/gram.y modified +43 −22
src/backend/parser/parse_relation.c modified +1 −1
src/backend/parser/parse_target.c modified +2 −1
src/backend/parser/parse_utilcmd.c modified +242 −98
src/backend/utils/adt/ruleutils.c modified +31 −0
src/backend/utils/adt/selfuncs.c modified +2 −2
src/backend/utils/cache/relcache.c modified +50 −37
src/backend/utils/sort/tuplesort.c modified +2 −3
src/bin/pg_dump/pg_dump.c modified +34 −6
src/bin/pg_dump/pg_dump.h modified +4 −2
src/include/access/amapi.h modified +2 −0
src/include/access/hash.h modified +1 −1
src/include/access/itup.h modified +5 −2
src/include/access/nbtree.h modified +65 −26
src/include/access/nbtxlog.h modified +7 −5
src/include/catalog/catversion.h modified +1 −1
src/include/catalog/pg_constraint_fn.h modified +1 −0
src/include/catalog/pg_constraint.h modified +15 −8
src/include/catalog/pg_index.h modified +20 −18
src/include/nodes/execnodes.h modified +6 −3
src/include/nodes/parsenodes.h modified +6 −1
src/include/nodes/relation.h modified +8 −5
src/include/parser/kwlist.h modified +1 −0
src/include/utils/rel.h modified +15 −1
src/test/isolation/specs/insert-conflict-do-nothing-2.spec modified +1 −1
src/test/isolation/specs/insert-conflict-do-update-2.spec modified +1 −1
src/test/isolation/specs/lock-committed-keyupdate.spec modified +1 −1
src/test/isolation/specs/lock-update-traversal.spec modified +3 −2
src/test/regress/expected/create_index.out modified +19 −0
src/test/regress/expected/index_including.out added +346 −0
src/test/regress/parallel_schedule modified +1 −1
src/test/regress/serial_schedule modified +1 −0
src/test/regress/sql/create_index.sql modified +20 −0
src/test/regress/sql/index_including.sql added +203 −0
src/test/subscription/t/001_rep_changes.pl modified +17 −2

Documentation touched

Discussion