| From: | Chengpeng Yan <chengpeng_yan(at)outlook(dot)com> |
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com> |
| Subject: | Re: [PATCH] Fix encoding-dependent LIKE/regex selectivity estimates |
| Date: | 2026-11-25 05:30:37 |
| Message-ID: | 8D7CDE65-25F3-4087-8B9E-7E416CAF30D3@outlook.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
> On Nov 25, 2026, at 00:12, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> I don't quite agree with that definition: a length restriction is
> not "no constraint". But that's a side point.
>
> Yes, we could distinguish cases where the pattern is like "abc%"
> or "^abc", and maybe that's common enough to be worth the trouble,
> but I'm not really convinced. I think when we put in the
> check-all-the-histogram-entries logic we eliminated pretty much
> all reason to work hard on pattern analysis. The fixed-prefix
> logic is worth keeping because it allows a preliminary index-based
> filter, but I think we should stop with that rather than trying
> to do fragmentary pattern analysis.
>
> regards, tom lane
Agreed. I will not do any further analysis of the pattern: rest_selec
becomes DEFAULT_MATCH_SEL, and everything that was used to compute it is
removed:
heursel = prefixsel * rest_selec; <- today
heursel = prefixsel * DEFAULT_MATCH_SEL; <- proposed
One test result changes: one EXPLAIN in the statistics-privileges block of
inherit.sql goes from hash join to nested loop. With no stats available
its estimate was about 4% (counting the pattern's characters) and is now
0.5%, so the plan changes as expected.
If we want the test to keep telling us, through the join method, whether
the stats were usable, I would change the pattern from 'a1$' to
'^[0-9a-f]', so that it matches almost every value: with the stats it
estimates 100% and picks a hash join, without them the 0.5% fallback picks
a nested loop. Any other idea, or should I just update the expected
output?
--
Best regards,
Chengpeng Yan
| Attachment | Content-Type | Size |
|---|---|---|
| v3-0001-Simplify-pattern-selectivity-estimation.patch | application/octet-stream | 15.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nisha Moond | 2026-11-25 05:43:38 | Re: Proposal: Conflict log history table for Logical Replication |
| Previous Message | Aleksander Alekseev | 2026-11-25 05:16:56 | Re: [PATCH] plpgsql: detoast a returned record before keeping it in a non-atomic context |