postgresql/src/include
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
..
access Avoid full scan of GIN indexes when possible 2020-01-18 01:11:39 +03:00
bootstrap Update copyrights for 2020 2020-01-01 12:21:45 -05:00
catalog bump catalog version as should have been done for jsonb_set_lax 2020-01-17 16:24:13 +10:30
commands Restructure ALTER TABLE execution to fix assorted bugs. 2020-01-15 18:49:24 -05:00
common Move OpenSSL routines for min/max protocol setting to src/common/ 2020-01-17 10:06:17 +09:00
datatype Update copyrights for 2020 2020-01-01 12:21:45 -05:00
executor Improve the handling of result type coercions in SQL functions. 2020-01-08 11:07:59 -05:00
fe_utils Reduce size of backend scanner's tables. 2020-01-13 15:04:31 -05:00
foreign Update copyrights for 2020 2020-01-01 12:21:45 -05:00
jit Update copyrights for 2020 2020-01-01 12:21:45 -05:00
lib Skip memcpy(x, x) in qunique(). 2020-01-04 11:31:42 -08:00
libpq Update copyrights for 2020 2020-01-01 12:21:45 -05:00
mb Rationalize code placement between wchar.c, encnames.c, and mbutils.c. 2020-01-16 18:08:21 -05:00
nodes Repair more failures with SubPlans in multi-row VALUES lists. 2020-01-17 16:17:31 -05:00
optimizer Update copyrights for 2020 2020-01-01 12:21:45 -05:00
parser Restructure ALTER TABLE execution to fix assorted bugs. 2020-01-15 18:49:24 -05:00
partitioning Update copyrights for 2020 2020-01-01 12:21:45 -05:00
port Update copyrights for 2020 2020-01-01 12:21:45 -05:00
portability Update copyrights for 2020 2020-01-01 12:21:45 -05:00
postmaster Update copyrights for 2020 2020-01-01 12:21:45 -05:00
regex Update copyrights for 2020 2020-01-01 12:21:45 -05:00
replication Set ReorderBufferTXN->final_lsn more eagerly 2020-01-17 18:00:39 -03:00
rewrite Update copyrights for 2020 2020-01-01 12:21:45 -05:00
snowball Update copyrights for 2020 2020-01-01 12:21:45 -05:00
statistics Update copyrights for 2020 2020-01-01 12:21:45 -05:00
storage Remove STATUS_FOUND 2020-01-11 07:48:57 +01:00
tcop Fix problems with "read only query" checks, and refactor the code. 2020-01-16 12:11:31 -05:00
tsearch Update copyrights for 2020 2020-01-01 12:21:45 -05:00
utils Report progress of ANALYZE commands 2020-01-15 11:14:39 -03:00
.gitignore Refactor dlopen() support 2018-09-06 11:33:04 +02:00
c.h Remove STATUS_FOUND 2020-01-11 07:48:57 +01:00
fmgr.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
funcapi.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
getaddrinfo.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
getopt_long.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
Makefile Get rid of jsonpath_gram.h and jsonpath_scanner.h 2019-03-20 11:13:34 +03:00
miscadmin.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
pg_config.h.in Fix handling of OpenSSL's SSL_clear_options 2019-12-06 15:13:55 +09:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
pg_getopt.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
pg_trace.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
pgstat.h Report progress of ANALYZE commands 2020-01-15 11:14:39 -03:00
pgtar.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
pgtime.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
port.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
postgres.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
postgres_ext.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
postgres_fe.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
rusagestub.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00
windowapi.h Update copyrights for 2020 2020-01-01 12:21:45 -05:00