Skip site navigation (1) Skip section navigation (2)

Re: BUG #5478: ILIKE operator returns wrong result

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Markus <markus(dot)herven(at)outpost24(dot)com>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5478: ILIKE operator returns wrong result
Date: 2010-05-28 15:38:29
Message-ID: 201005281538.o4SFcTW16083@momjian.us (view raw or flat)
Thread:
Lists: pgsql-bugs
Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)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.

I took a different approach.  I think the problem is that we check for
end of pattern without consuming '%' patterns.  I copied that consume
loop from code above that where we also test for end of pattern.

With the attached patch (which includes a regression test addition), it
works fine:

	test=> select 'ba' like '%__%';
	 ?column?
	----------
	 t
	(1 row)

-- 
  Bruce Momjian  <bruce(at)momjian(dot)us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

In response to

Responses

pgsql-bugs by date

Next:From: Tom LaneDate: 2010-05-28 15:51:08
Subject: Re: BUG #5478: ILIKE operator returns wrong result
Previous:From: Tom LaneDate: 2010-05-28 15:34:52
Subject: Re: BUG #5478: ILIKE operator returns wrong result

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group