postgresql/src/include/access
Alexander Korotkov 4b754d6c16 Avoid full scan of GIN indexes when possible
The strategy of GIN index scan is driven by opclass-specific extract_query
method.  This method that needed search mode is GIN_SEARCH_MODE_ALL.  This
mode means that matching tuple may contain none of extracted entries.  Simple
example is '!term' tsquery, which doesn't need any term to exist in matching
tsvector.

In order to handle such scan key GIN calculates virtual entry, which contains
all TIDs of all entries of attribute.  In fact this is full scan of index
attribute.  And typically this is very slow, but allows to handle some queries
correctly in GIN.  However, current algorithm calculate such virtual entry for
each GIN_SEARCH_MODE_ALL scan key even if they are multiple for the same
attribute.  This is clearly not optimal.

This commit improves the situation by introduction of "exclude only" scan keys.
Such scan keys are not capable to return set of matching TIDs.  Instead, they
are capable only to filter TIDs produced by normal scan keys.  Therefore,
each attribute should contain at least one normal scan key, while rest of them
may be "exclude only" if search mode is GIN_SEARCH_MODE_ALL.

The same optimization might be applied to the whole scan, not per-attribute.
But that leads to NULL values elimination problem.  There is trade-off between
multiple possible ways to do this.  We probably want to do this later using
some cost-based decision algorithm.

Discussion: https://postgr.es/m/CAOBaU_YGP5-BEt5Cc0%3DzMve92vocPzD%2BXiZgiZs1kjY0cj%3DXBg%40mail.gmail.com
Author: Nikita Glukhov, Alexander Korotkov, Tom Lane, Julien Rouhaud
Reviewed-by: Julien Rouhaud, Tomas Vondra, Tom Lane
2020-01-18 01:11:39 +03:00
..
amapi.h Introduce IndexAM fields for parallel vacuum. 2020-01-15 07:24:14 +05:30
amvalidate.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
attmap.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
attnum.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
brin.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
brin_internal.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
brin_page.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
brin_pageops.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
brin_revmap.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
brin_tuple.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
brin_xlog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
bufmask.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
clog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
commit_ts.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
detoast.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
genam.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
generic_xlog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
gin.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
gin_private.h Avoid full scan of GIN indexes when possible 2020-01-18 01:11:39 +03:00
ginblock.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
ginxlog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
gist.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
gist_private.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
gistscan.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
gistxlog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
hash.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
hash_xlog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
heapam.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
heapam_xlog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
heaptoast.h tableam: New callback relation_fetch_toast_slice. 2020-01-07 14:36:38 -05:00
hio.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
htup.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
htup_details.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
itup.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
multixact.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
nbtree.h nbtree: Rename BT_HEAP_TID_ATTR. 2020-01-10 13:15:28 -08:00
nbtxlog.h Add xl_btree_delete optimization. 2020-01-03 12:18:13 -08:00
parallel.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
printsimple.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
printtup.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
relation.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
reloptions.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
relscan.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
rewriteheap.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
rmgr.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
rmgrlist.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
sdir.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
session.h Fix typo. 2020-01-13 14:44:55 +05:30
skey.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
slru.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
spgist.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
spgist_private.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
spgxlog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
stratnum.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
subtrans.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
sysattr.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
table.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
tableam.h Remove bogus 'return'. 2020-01-09 09:01:37 -05:00
timeline.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
toast_helper.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
toast_internals.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
transam.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
tsmapi.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
tupconvert.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
tupdesc.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
tupdesc_details.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
tupmacs.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
twophase.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
twophase_rmgr.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
valid.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
visibilitymap.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
xact.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
xlog.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
xlog_internal.h Add xl_btree_delete optimization. 2020-01-03 12:18:13 -08:00
xlogdefs.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
xloginsert.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
xlogreader.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
xlogrecord.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
xlogutils.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00