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

Re: [HACKERS] like/ilike improvements

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Zeugswetter Andreas ADI SD <ZeugswetterA(at)spardat(dot)at>, andrew(at)supernews(dot)com, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] like/ilike improvements
Date: 2007-06-01 22:54:04
Message-ID: 25250.1180738444@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> OK, here is a patch that I think incorporates all the ideas discussed 
> (including part of Mark Mielke's suggestion about optimising %_). There 
> is now no special treatment of UTF8 other than its use of a faster 
> NextChar macro.

Looks mostly pretty good.  I would suggest replacing tests "tlen == 0"
and "plen == 0" with "<= 0", just so the code doesn't go completely
insane if presented with invalidly-encoded data that causes it to step
beyond the end of data.  Also, this comment is not really good enough:

> ! 		/*
> ! 		 * It is safe to use NextByte instead of NextChar here, even for
> ! 		 * multi-byte character sets, because we are not following 
> ! 		 * immediately after a wildcard character.
> ! 		 */
> ! 		NextByte(t, tlen);
> ! 		NextByte(p, plen);
>   	}

I'd suggest adding something like "If we are in the middle of a
multibyte character, we must already have matched at least one byte of
the character from both text and pattern; so we cannot get out-of-sync
on character boundaries.  And we know that no backend-legal encoding
allows ASCII characters such as '%' to appear as non-first bytes of
characters, so we won't mistakenly detect a new wildcard."

			regards, tom lane

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2007-06-01 22:58:18
Subject: Re: [HACKERS] like/ilike improvements
Previous:From: Jim NasbyDate: 2007-06-01 22:53:56
Subject: Re: [HACKERS] table partitioning pl/pgsql helpers

pgsql-patches by date

Next:From: Tom LaneDate: 2007-06-01 22:58:18
Subject: Re: [HACKERS] like/ilike improvements
Previous:From: Bruce MomjianDate: 2007-06-01 21:11:36
Subject: Re: [pgsql-patches] Ctid chain following enhancement

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