Re: Support LIKE with nondeterministic collations

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>, Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com>
Cc: 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-11 13:25:29
Message-ID: bce1da9a-2975-462f-8946-c58c878ba82c@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 04/11/2024 10:26, Peter Eisentraut wrote:
> On 29.10.24 18:15, Jacob Champion wrote:
>> libfuzzer is unhappy about the following code in MatchText:
>>
>>> +            while (p1len > 0)
>>> +            {
>>> +                if (*p1 == '\\')
>>> +                {
>>> +                    found_escape = true;
>>> +                    NextByte(p1, p1len);
>>> +                }
>>> +                else if (*p1 == '_' || *p1 == '%')
>>> +                    break;
>>> +                NextByte(p1, p1len);
>>> +            }
>>
>> If the pattern ends with a backslash, we'll call NextByte() twice,
>> p1len will wrap around to INT_MAX, and we'll walk off the end of the
>> buffer. (I fixed it locally by duplicating the ERROR case that's
>> directly above this.)
>
> Thanks.  Here is an updated patch with that fixed.

Sadly the algorithm is O(n^2) with non-deterministic collations.Is there
any way this could be optimized? We make no claims on how expensive any
functions or operators are, so I suppose a slow implementation is
nevertheless better than throwing an error.

Let's at least add some CHECK_FOR_INTERRUPTS(). For example, this takes
a very long time and is uninterruptible:

SELECT repeat('x', 100000) LIKE '%xxxy%' COLLATE ignore_accents;

--
Heikki Linnakangas
Neon (https://neon.tech)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashutosh Bapat 2024-11-11 13:51:04 Re: logical replication: restart_lsn can go backwards (and more), seems broken since 9.4
Previous Message Hayato Kuroda (Fujitsu) 2024-11-11 13:08:43 RE: Parallel heap vacuum