]> granicus.if.org Git - postgresql/commit
Allow index AMs to cache data across aminsert calls within a SQL command.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 9 Feb 2017 16:52:12 +0000 (11:52 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 9 Feb 2017 16:52:12 +0000 (11:52 -0500)
commit86d911ec0f9d4643e9a47db42510959dec0ed76b
treeef0605eb3b8357a406b51dc22d25206a39cbc561
parent7c5d8c16e12e56c1043ff4a28e07a306a15c2b85
Allow index AMs to cache data across aminsert calls within a SQL command.

It's always been possible for index AMs to cache data across successive
amgettuple calls within a single SQL command: the IndexScanDesc.opaque
field is meant for precisely that.  However, no comparable facility
exists for amortizing setup work across successive aminsert calls.
This patch adds such a feature and teaches GIN, GIST, and BRIN to use it
to amortize catalog lookups they'd previously been doing on every call.
(The other standard index AMs keep everything they need in the relcache,
so there's little to improve there.)

For GIN, the overall improvement in a statement that inserts many rows
can be as much as 10%, though it seems a bit less for the other two.
In addition, this makes a really significant difference in runtime
for CLOBBER_CACHE_ALWAYS tests, since in those builds the repeated
catalog lookups are vastly more expensive.

The reason this has been hard up to now is that the aminsert function is
not passed any useful place to cache per-statement data.  What I chose to
do is to add suitable fields to struct IndexInfo and pass that to aminsert.
That's not widening the index AM API very much because IndexInfo is already
within the ken of ambuild; in fact, by passing the same info to aminsert
as to ambuild, this is really removing an inconsistency in the AM API.

Discussion: https://postgr.es/m/27568.1486508680@sss.pgh.pa.us
26 files changed:
contrib/bloom/blinsert.c
contrib/bloom/bloom.h
doc/src/sgml/indexam.sgml
src/backend/access/brin/brin.c
src/backend/access/gin/gininsert.c
src/backend/access/gist/gist.c
src/backend/access/hash/hash.c
src/backend/access/heap/tuptoaster.c
src/backend/access/index/indexam.c
src/backend/access/nbtree/nbtree.c
src/backend/access/spgist/spginsert.c
src/backend/catalog/index.c
src/backend/catalog/indexing.c
src/backend/catalog/toasting.c
src/backend/commands/constraint.c
src/backend/commands/indexcmds.c
src/backend/executor/execIndexing.c
src/include/access/amapi.h
src/include/access/brin_internal.h
src/include/access/genam.h
src/include/access/gin_private.h
src/include/access/gist_private.h
src/include/access/hash.h
src/include/access/nbtree.h
src/include/access/spgist.h
src/include/nodes/execnodes.h