postgresql/contrib/pg_trgm
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
..
data Add files forgotten in f576b17cd6 2016-03-16 19:23:41 +03:00
expected Avoid full scan of GIN indexes when possible 2020-01-18 01:11:39 +03:00
sql Avoid full scan of GIN indexes when possible 2020-01-18 01:11:39 +03:00
.gitignore Support "make check" in contrib 2011-04-25 22:27:11 +03:00
Makefile Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
pg_trgm--1.0--1.1.sql Fix typo in update scripts for some contrib modules. 2013-07-19 04:13:01 +09:00
pg_trgm--1.1--1.2.sql Add word_similarity to pg_trgm contrib module. 2016-03-16 18:59:21 +03:00
pg_trgm--1.2--1.3.sql pg_trgm's set_limit() function is parallel unsafe, not parallel restricted. 2016-06-20 11:29:54 -04:00
pg_trgm--1.3--1.4.sql Add strict_word_similarity to pg_trgm module 2018-03-21 14:57:42 +03:00
pg_trgm--1.3.sql pg_trgm's set_limit() function is parallel unsafe, not parallel restricted. 2016-06-20 11:29:54 -04:00
pg_trgm--unpackaged--1.0.sql Fix typos in some error messages thrown by extension scripts when fed to psql. 2014-08-25 18:30:37 +02:00
pg_trgm.control Add strict_word_similarity to pg_trgm module 2018-03-21 14:57:42 +03:00
trgm.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
trgm_gin.c Make the order of the header file includes consistent in contrib modules. 2019-10-24 08:05:34 +05:30
trgm_gist.c Make the order of the header file includes consistent in contrib modules. 2019-10-24 08:05:34 +05:30
trgm_op.c Add reusable routine for making arrays unique. 2019-11-07 17:00:48 +13:00
trgm_regexp.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00