pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Simplify pattern selectivity estimation.
Date: Wed, 25 Nov 2026 22:17:00 +0000
Message-ID: <E1xWLIS-00000000JqM-3jDK@gemulon.postgresql.org> (raw)

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@outlook.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.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(-)



Message-ID: <E1xWLIS-00000000JqM-3jDK@gemulon.postgresql.org>
Permalink:  ../E1xWLIS-00000000JqM-3jDK@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xWLIS-00000000JqM-3jDK@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Simplify pattern selectivity estimation.
  In-Reply-To: <E1xWLIS-00000000JqM-3jDK@gemulon.postgresql.org>
  References: <E1xWLIS-00000000JqM-3jDK@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox