Re: Support LIKE with nondeterministic collations

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Daniel Verite <daniel(at)manitou-mail(dot)org>, Paul A Jungwirth <pj(at)illuminatedcomputing(dot)com>
Subject: Re: Support LIKE with nondeterministic collations
Date: 2024-11-19 13:51:03
Message-ID: d57efd38-3db0-40b7-999c-d26bc9259616@eisentraut.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 18.11.24 04:30, jian he wrote:
> we can optimize when trailing (last character) is not wildcards.
>
> SELECT 'Ha12foo' LIKE '%foo' COLLATE ignore_accents;
> within the for loop
> for(;;)
> {
> int cmp;
> CHECK_FOR_INTERRUPTS();
> ....
> }
>
> pg_strncoll comparison will become
> Ha12foo foo
> a12foo foo
> 12foo foo
> 2foo foo
> foo foo
>
> it's safe because in MatchText we have:
> else if (*p == '%')
> {
> while (tlen > 0)
> {
> if (GETCHAR(*t, locale) == firstpat || (locale && !locale->deterministic))
> {
> int matched = MatchText(t, tlen, p, plen, locale);
> if (matched != LIKE_FALSE)
> return matched; /* TRUE or ABORT */
> }
> NextChar(t, tlen);
> }
> }
>
> please check attached.

I see, good idea. I implemented it a bit differently. See "Shortcut:
If this is the end of the pattern ..." in this patch. Please check if
this is what you had in mind.

Attachment Content-Type Size
v8-0001-Support-LIKE-with-nondeterministic-collations.patch text/plain 26.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ilia Evdokimov 2024-11-19 14:23:01 Re: Sample rate added to pg_stat_statements
Previous Message Shlok Kyal 2024-11-19 13:42:28 Re: Disallow UPDATE/DELETE on table with unpublished generated column as REPLICA IDENTITY