1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-08 00:47:37 +03:00

Go back to using a separate method for doing ILIKE for single byte

character encodings that doesn't involve calling lower(). This should
cure the performance regression in this case complained of by Guillaume
Smet. It still leaves the horrid performance for multi-byte encodings
introduced in 8.2, but there's no obvious solution for that in sight.
This commit is contained in:
Andrew Dunstan
2007-09-22 03:58:34 +00:00
parent b5d1608b0a
commit e152893305
2 changed files with 55 additions and 17 deletions

View File

@@ -3,8 +3,9 @@
* like_match.c
* like expression handling internal code.
*
* This file is included by like.c three times, to provide natching code for
* single-byte encodings, UTF8, and for other multi-byte encodings.
* This file is included by like.c four times, to provide natching code for
* single-byte encodings, UTF8, and for other multi-byte encodings,
* and case insensitive matches for single byte encodings.
* UTF8 is a special case because we can use a much more efficient version
* of NextChar than can be used for other multi-byte encodings.
*
@@ -13,11 +14,12 @@
* NextChar
* MatchText - to name of function wanted
* do_like_escape - name of function if wanted - needs CHAREQ and CopyAdvChar
* MATCH_LOWER - define iff using to_lower on text chars
*
* Copyright (c) 1996-2007, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.17 2007/09/21 22:52:52 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.18 2007/09/22 03:58:34 adunstan Exp $
*
*-------------------------------------------------------------------------
*/
@@ -68,6 +70,12 @@
*--------------------
*/
#ifdef MATCH_LOWER
#define TCHAR(t) tolower((t))
#else
#define TCHAR(t) (t)
#endif
static int
MatchText(char *t, int tlen, char *p, int plen)
{
@@ -143,13 +151,13 @@ MatchText(char *t, int tlen, char *p, int plen)
else
{
char firstpat = *p ;
char firstpat = TCHAR(*p) ;
if (*p == '\\')
{
if (plen < 2)
return LIKE_FALSE;
firstpat = p[1];
firstpat = TCHAR(p[1]);
}
while (tlen > 0)
@@ -158,7 +166,7 @@ MatchText(char *t, int tlen, char *p, int plen)
* Optimization to prevent most recursion: don't recurse
* unless first pattern byte matches first text byte.
*/
if (*t == firstpat)
if (TCHAR(*t) == firstpat)
{
int matched = MatchText(t, tlen, p, plen);
@@ -183,7 +191,7 @@ MatchText(char *t, int tlen, char *p, int plen)
NextByte(p, plen);
continue;
}
else if (*t != *p)
else if (TCHAR(*t) != TCHAR(*p))
{
/*
* Not the single-character wildcard and no explicit match? Then
@@ -338,3 +346,8 @@ do_like_escape(text *pat, text *esc)
#undef do_like_escape
#endif
#undef TCHAR
#ifdef MATCH_LOWER
#undef MATCH_LOWER
#endif