| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Simplify pattern selectivity estimation. |
| Date: | 2026-11-25 22:17:00 |
| Message-ID: | E1xWLIS-00000000JqM-3jDK@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Simplify pattern selectivity estimation.
Remove a couple hundred lines of ancient code that purported to
estimate the selectivity of LIKE and regex patterns. This code was
fundamentally bogus in several ways: the estimation rules it used
didn't have much foundation in reality, it could produce different
results depending on database encoding, and its understanding of regex
syntax was far short of adequate. Moreover, we don't really need it
since we installed the histogram_selectivity() machinery: in just
about all practical cases, we will get a far-more-trustworthy
selectivity estimate by seeing how many of the histogram and MCV
list entries match the pattern. So rip all that out, and just use
DEFAULT_MATCH_SEL to represent the selectivity of the non-prefix part
of the pattern when we don't have adequate statistics. (We keep the
prefix-match logic, since we'd want that anyway to permit indexscan
optimizations.)
This change requires rejiggering one set of tests in inherit.sql
so that they continue to prove what they're supposed to about
statistics being inaccessible to users without adequate permissions.
The default selectivity of the regex operator is now small enough to
cause the test query to be planned as a nestloop, so change the
pattern to select a large fraction not a small fraction of the rows.
This flips the choice between hash and nestloop plans, which is fine
since the point is just to show that hiding the statistics matters.
Author: Chengpeng Yan <chengpeng_yan(at)outlook(dot)com>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/124D8863-5FFE-412A-B2E1-D07ACBD8FA38@outlook.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/31878ccc2cd5642a5d2a1a39dedb79e9a18c8a07
Modified Files
--------------
src/backend/utils/adt/like_support.c | 298 +++-------------------------------
src/test/regress/expected/inherit.out | 66 ++++----
src/test/regress/sql/inherit.sql | 10 +-
3 files changed, 63 insertions(+), 311 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Masahiko Sawada | 2026-11-25 18:55:06 | pgsql: doc: Clarify that logical decoding message LSN is the end LSN. |