postgresql/src/backend
Tom Lane a80818605e Improve selectivity estimation for assorted match-style operators.
Quite a few matching operators such as JSONB's @> used "contsel" and
"contjoinsel" as their selectivity estimators.  That was a bad idea,
because (a) contsel is only a stub, yielding a fixed default estimate,
and (b) that default is 0.001, meaning we estimate these operators as
five times more selective than equality, which is surely pretty silly.

There's a good model for improving this in ltree's ltreeparentsel():
for any "var OP constant" query, we can try applying the operator
to all of the column's MCV and histogram values, taking the latter
as being a random sample of the non-MCV values.  That code is
actually 100% generic, except for the question of exactly what
default selectivity ought to be plugged in when we don't have stats.

Hence, migrate the guts of ltreeparentsel() into the core code, provide
wrappers "matchingsel" and "matchingjoinsel" with a more-appropriate
default estimate, and use those for the non-geometric operators that
formerly used contsel (mostly JSONB containment operators and tsquery
matching).

Also apply this code to some match-like operators in hstore, ltree, and
pg_trgm, including the former users of ltreeparentsel as well as ones
that improperly used contsel.  Since commit 911e70207 just created new
versions of those extensions that we haven't released yet, we can sneak
this change into those new versions instead of having to create an
additional generation of update scripts.

Patch by me, reviewed by Alexey Bashtanov

Discussion: https://postgr.es/m/12237.1582833074@sss.pgh.pa.us
2020-04-01 10:32:33 -04:00
..
access Add CREATE INDEX deduplication assertions. 2020-03-31 14:38:39 -07:00
bootstrap Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:09 -07:00
catalog Update SQL features 2020-03-31 08:25:03 +02:00
commands Fix coverity complaint about commit 40d964ec99. 2020-04-01 09:28:13 +05:30
executor Allow the planner-related functions and hook to accept the query string. 2020-03-30 13:51:05 +09:00
foreign Update copyrights for 2020 2020-01-01 12:21:45 -05:00
jit Extend ExecBuildAggTrans() to support a NULL pointer check. 2020-03-04 17:29:18 -08:00
lib Move src/backend/utils/hash/hashfn.c to src/common 2020-02-27 09:25:41 +05:30
libpq Provide a TLS init hook 2020-03-25 17:13:17 -04:00
main Add PostgreSQL home page to --help output 2020-02-28 13:12:21 +01:00
nodes Implement operator class parameters 2020-03-30 19:17:23 +03:00
optimizer Implement operator class parameters 2020-03-30 19:17:23 +03:00
parser Implement operator class parameters 2020-03-30 19:17:23 +03:00
partitioning Add object names to partition integrity violations. 2020-03-23 08:09:15 +05:30
po Translation updates 2019-06-17 15:30:20 +02:00
port Update copyrights for 2020 2020-01-01 12:21:45 -05:00
postmaster Trigger autovacuum based on number of INSERTs 2020-03-28 19:20:12 +13:00
regex Update copyrights for 2020 2020-01-01 12:21:45 -05:00
replication Refactor code to look up local replication tuple 2020-04-01 15:34:41 +02:00
rewrite Fix INSERT OVERRIDING USER VALUE behavior 2020-03-31 08:50:39 +02:00
snowball Update copyrights for 2020 2020-01-01 12:21:45 -05:00
statistics Fix race condition in statext_store(). 2020-03-31 17:06:22 -04:00
storage Fix assorted typos 2020-03-31 16:00:06 +02:00
tcop Fix assorted typos 2020-03-31 16:00:06 +02:00
tsearch Remove useless pfree()s at the ends of various ValuePerCall SRFs. 2020-03-16 21:36:53 -04:00
utils Improve selectivity estimation for assorted match-style operators. 2020-04-01 10:32:33 -04:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Update copyrights for 2020 2020-01-01 12:21:45 -05:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
nls.mk Translation updates 2019-05-20 16:00:53 +02:00