Re: Support LIKE with nondeterministic collations

Peter Eisentraut <peter@eisentraut.org>

From: Peter Eisentraut <peter@eisentraut.org>
To: jian he <jian.universality@gmail.com>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>, Jacob Champion <jacob.champion@enterprisedb.com>, pgsql-hackers <pgsql-hackers@postgresql.org>, Daniel Verite <daniel@manitou-mail.org>, Paul A Jungwirth <pj@illuminatedcomputing.com>
Date: 2024-11-19T13:51:03Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Support LIKE with nondeterministic collations

Attachments

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.