Re: BUG #5478: ILIKE operator returns wrong result - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #5478: ILIKE operator returns wrong result
Date
Msg-id 26124.1275060892@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #5478: ILIKE operator returns wrong result  (Bruce Momjian <bruce@momjian.us>)
Responses Re: BUG #5478: ILIKE operator returns wrong result  (Bruce Momjian <bruce@momjian.us>)
List pgsql-bugs
Bruce Momjian <bruce@momjian.us> writes:
> Tom Lane wrote:
>> I have a feeling that this represents still another bug in the
>> special-case path for % followed by _ (cf bug #4821).  If so,
>> maybe we ought to just toss out that optimization?

> Yea, looks like it is this code in like_match.c:

No, actually it's the bit right after that:

                /* Look for a place that matches the rest of the pattern */
                while (tlen > 0)
                {
                    int            matched = MatchText(t, tlen, p, plen);

                    if (matched != LIKE_FALSE)
                        return matched; /* TRUE or ABORT */

                    NextChar(t, tlen);
                }

If tlen == 0 when we reach this loop, we'll fall through and fail.
But that is wrong since we need to consider the possibility that
the remaining pattern can match a zero-length substring.  So the
loop needs to be changed to attempt a recursive MatchText for
tlen equal to zero as well as greater than zero.

            regards, tom lane

pgsql-bugs by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: BUG #5478: ILIKE operator returns wrong result
Next
From: Bruce Momjian
Date:
Subject: Re: BUG #5478: ILIKE operator returns wrong result