Re: [PATCH] Fix encoding-dependent LIKE/regex selectivity estimates

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Chengpeng Yan <chengpeng_yan(at)outlook(dot)com>
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-19 01:25:45
Message-ID: 928257.1795051545@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I wrote:
> I'm not sure what I think about this proposal. I agree it looks dumb
> to estimate the selectivity of "é" differently from "e", and even more
> so for it to depend on the encoding. However, I believe this per-byte
> counting was intentional, with an eye to Far Eastern character sets.
> A single ideogram of Chinese or Japanese probably carries about the
> same selectivity as a word of English, so giving it the same
> selectivity as "e" likewise doesn't sound great. I'm not trying to
> claim that per-byte counting is ideal, but there is more here than
> meets the eye, so I'm loath to change a longstanding behavior on
> the basis of no discussion or evidence. How can we arrive at a
> behavior that is sensible for both of those cases?

After noodling about that for awhile, I have a potential answer.
Basically we need (I think) to distinguish letter-y characters
from ideogram-y characters. But there is a serviceable, and
fast, approximation to that in our infrastructure already:
check pg_encoding_dsplen() and see if it's 1 or 2. Double-width
characters can be counted on to carry more information than
regular-width ones. I don't have an immediate proposal about
what selectivity multiplier to assign to double-width characters,
but this approach seems like there's potential to accomplish
what the original hack hoped for without the encoding dependency.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Joao Rito 2026-11-19 01:30:03 [PATCH] pg_upgrade: add hints to wal_level and max_replication_slots checks
Previous Message Joao Rito 2026-11-19 01:08:03 Re: XMLTable treats a column of a domain over xml as a non-xml column