Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite152893

Browse files
committed
Go back to using a separate method for doing ILIKE for single byte
character encodings that doesn't involve calling lower(). This shouldcure the performance regression in this case complained of by GuillaumeSmet. It still leaves the horrid performance for multi-byte encodingsintroduced in 8.2, but there's no obvious solution for that in sight.
1 parentb5d1608 commite152893

File tree

2 files changed

+55
-17
lines changed

2 files changed

+55
-17
lines changed

‎src/backend/utils/adt/like.c

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
1313
* IDENTIFICATION
14-
*$PostgreSQL: pgsql/src/backend/utils/adt/like.c,v 1.70 2007/09/21 22:52:52 tgl Exp $
14+
*$PostgreSQL: pgsql/src/backend/utils/adt/like.c,v 1.71 2007/09/22 03:58:34 adunstan Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -36,6 +36,8 @@ static text *MB_do_like_escape(text *, text *);
3636

3737
staticintUTF8_MatchText(char*t,inttlen,char*p,intplen);
3838

39+
staticintSB_IMatchText(char*t,inttlen,char*p,intplen);
40+
3941
staticintGenericMatchText(char*s,intslen,char*p,intplen);
4042
staticintGeneric_Text_IC_like(text*str,text*pat);
4143

@@ -104,6 +106,12 @@ wchareq(char *p1, char *p2)
104106

105107
#include"like_match.c"
106108

109+
/* setup to compile like_match.c for single byte case insensitive matches */
110+
#defineMATCH_LOWER
111+
#defineNextChar(p,plen) NextByte((p), (plen))
112+
#defineMatchText SB_IMatchText
113+
114+
#include"like_match.c"
107115

108116
/* setup to compile like_match.c for UTF8 encoding, using fast NextChar */
109117

@@ -132,16 +140,33 @@ Generic_Text_IC_like(text *str, text *pat)
132140
intslen,
133141
plen;
134142

135-
/* Force inputs to lower case to achieve case insensitivity */
136-
str=DatumGetTextP(DirectFunctionCall1(lower,PointerGetDatum(str)));
137-
pat=DatumGetTextP(DirectFunctionCall1(lower,PointerGetDatum(pat)));
138-
/* lower's result is never packed, so OK to use old macros here */
139-
s=VARDATA(str);
140-
slen= (VARSIZE(str)-VARHDRSZ);
141-
p=VARDATA(pat);
142-
plen= (VARSIZE(pat)-VARHDRSZ);
143+
/* For efficiency reasons, in the single byte case we don't call
144+
* lower() on the pattern and text, but instead call to_lower on each
145+
* character. In the multi-byte case we don't have much choice :-(
146+
*/
143147

144-
returnGenericMatchText(s,slen,p,plen);
148+
if (pg_database_encoding_max_length()>1)
149+
{
150+
/* lower's result is never packed, so OK to use old macros here */
151+
pat=DatumGetTextP(DirectFunctionCall1(lower,PointerGetDatum(pat)));
152+
p=VARDATA(pat);
153+
plen= (VARSIZE(pat)-VARHDRSZ);
154+
str=DatumGetTextP(DirectFunctionCall1(lower,PointerGetDatum(str)));
155+
s=VARDATA(str);
156+
slen= (VARSIZE(str)-VARHDRSZ);
157+
if (GetDatabaseEncoding()==PG_UTF8)
158+
returnUTF8_MatchText(s,slen,p,plen);
159+
else
160+
returnMB_MatchText(s,slen,p,plen);
161+
}
162+
else
163+
{
164+
p=VARDATA_ANY(pat);
165+
plen=VARSIZE_ANY_EXHDR(pat);
166+
s=VARDATA_ANY(str);
167+
slen=VARSIZE_ANY_EXHDR(str);
168+
returnSB_IMatchText(s,slen,p,plen);
169+
}
145170
}
146171

147172
/*

‎src/backend/utils/adt/like_match.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
* like_match.c
44
* like expression handling internal code.
55
*
6-
* This file is included by like.c three times, to provide natching code for
7-
* single-byte encodings, UTF8, and for other multi-byte encodings.
6+
* This file is included by like.c four times, to provide natching code for
7+
* single-byte encodings, UTF8, and for other multi-byte encodings,
8+
* and case insensitive matches for single byte encodings.
89
* UTF8 is a special case because we can use a much more efficient version
910
* of NextChar than can be used for other multi-byte encodings.
1011
*
@@ -13,11 +14,12 @@
1314
* NextChar
1415
* MatchText - to name of function wanted
1516
* do_like_escape - name of function if wanted - needs CHAREQ and CopyAdvChar
17+
* MATCH_LOWER - define iff using to_lower on text chars
1618
*
1719
* Copyright (c) 1996-2007, PostgreSQL Global Development Group
1820
*
1921
* IDENTIFICATION
20-
*$PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.17 2007/09/21 22:52:52 tgl Exp $
22+
*$PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.18 2007/09/22 03:58:34 adunstan Exp $
2123
*
2224
*-------------------------------------------------------------------------
2325
*/
@@ -68,6 +70,12 @@
6870
*--------------------
6971
*/
7072

73+
#ifdefMATCH_LOWER
74+
#defineTCHAR(t) tolower((t))
75+
#else
76+
#defineTCHAR(t) (t)
77+
#endif
78+
7179
staticint
7280
MatchText(char*t,inttlen,char*p,intplen)
7381
{
@@ -143,13 +151,13 @@ MatchText(char *t, int tlen, char *p, int plen)
143151
else
144152
{
145153

146-
charfirstpat=*p ;
154+
charfirstpat=TCHAR(*p) ;
147155

148156
if (*p=='\\')
149157
{
150158
if (plen<2)
151159
returnLIKE_FALSE;
152-
firstpat=p[1];
160+
firstpat=TCHAR(p[1]);
153161
}
154162

155163
while (tlen>0)
@@ -158,7 +166,7 @@ MatchText(char *t, int tlen, char *p, int plen)
158166
* Optimization to prevent most recursion: don't recurse
159167
* unless first pattern byte matches first text byte.
160168
*/
161-
if (*t==firstpat)
169+
if (TCHAR(*t)==firstpat)
162170
{
163171
intmatched=MatchText(t,tlen,p,plen);
164172

@@ -183,7 +191,7 @@ MatchText(char *t, int tlen, char *p, int plen)
183191
NextByte(p,plen);
184192
continue;
185193
}
186-
elseif (*t!=*p)
194+
elseif (TCHAR(*t)!=TCHAR(*p))
187195
{
188196
/*
189197
* Not the single-character wildcard and no explicit match? Then
@@ -338,3 +346,8 @@ do_like_escape(text *pat, text *esc)
338346
#undef do_like_escape
339347
#endif
340348

349+
#undef TCHAR
350+
351+
#ifdefMATCH_LOWER
352+
#undef MATCH_LOWER
353+
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp