Re: [PATCH] Add planner support function to two-argument regexp_like()

Поиск
Список
Период
Сортировка
Искать

Re: [PATCH] Add planner support function to two-argument regexp_like()

От:
jian he <jian.universality@gmail.com>
Дата:
On Wed, Jul 29, 2026 at 12:11 PM shihao zhong  wrote:
>
> Hi hackers,
>
> The ~ operator gets index conditions from a fixed pattern prefix, via
> textregexeq_support(). regexp_like(), which is the same test, has no
> support function and so misses out.
>
> With no flags the two are identical,

regexp_like_no_flags is the same as textregexeq,
therefore let the textregexeq support function also used in
regexp_like_no_flags is OK, i think.

we already have coverage for textregexeq_support,
https://coverage.postgresql.org/src/backend/utils/adt/like_support.c.gcov.html.
I tend to think V1 regression tests are unnecessary, but that's a minor point.



--
jian
https://www.enterprisedb.com/


Re: [PATCH] Add planner support function to two-argument regexp_like()

От:
shihao zhong <zhong950419@gmail.com>
Дата:
Вложения:
Hi Jian,

Thanks for reviewing my patch.

> we already have coverage for textregexeq_support,
> I tend to think V1 regression tests are unnecessary, but that's a minor point.

Agreed, v2 keeps one EXPLAIN that shows the Index Cond and drops the rest
of the tests.

Thanks,
Shihao 

Re: [PATCH] Add planner support function to two-argument regexp_like()

От:
shihao zhong <zhong950419@gmail.com>
Дата:
Вложения:
Rebase this patch with master


Re: [PATCH] Add planner support function to two-argument regexp_like()

От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Fri, Oct 9, 2026 at 12:51 PM shihao zhong  wrote:
>
> Rebase this patch with master

This patch introduces a row-count estimation regression when expression
index statistics are available for regexp_like(). For example:

-------------------------------------------------
CREATE TABLE t AS
SELECT CASE WHEN i <= 8000 THEN 'abc' ELSE 'xyz' END AS s,
       '^a'::text AS p
FROM generate_series(1, 10000) AS g(i);

CREATE INDEX ON t (regexp_like(s, p));
ANALYZE t;

EXPLAIN (ANALYZE, TIMING OFF)
SELECT * FROM t WHERE regexp_like(s, p);
-------------------------------------------------

With the patch, the estimate drops from 8,000 rows to 50, while
8,000 rows actually match. The support function returns the default
selectivity of 0.005 instead of allowing boolvarsel() to use the
expression index statistics.

Other functions, such as starts_with(), already have the same issue.
But, this patch introduces the problem for regexp_like(), so I think
we should address it together?

Regards,

-- 
Fujii Masao


Re: [PATCH] Add planner support function to two-argument regexp_like()

От:
shihao zhong <zhong950419@gmail.com>
Дата:
Вложения:
Hi Fujii-san,

Thanks, good catch.

0001 in v4 makes starts_with() and the LIKE and regex functions use
statistics on the call. 0002 is the regexp_like() patch on top. Your
example now estimates 8000 rows. Operators are unchanged. Both are
master only.


Thanks,
Shihao
FAQ