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

Commit7583f9a

Browse files
committed
Fix regex, LIKE, and some other second-rank text-manipulation functions
to not cause needless copying of text datums that have 1-byte headers.Greg Stark, in response to performance gripe from Guillaume Smet andITAGAKI Takahiro.
1 parentcc59049 commit7583f9a

File tree

6 files changed

+212
-192
lines changed

6 files changed

+212
-192
lines changed

‎src/backend/access/hash/hashfunc.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/hash/hashfunc.c,v 1.52 2007/06/01 15:33:18 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/hash/hashfunc.c,v 1.53 2007/09/21 22:52:52 tgl Exp $
1212
*
1313
* NOTES
1414
* These functions are stored in pg_amproc.For each operator class
@@ -157,16 +157,16 @@ hashname(PG_FUNCTION_ARGS)
157157
Datum
158158
hashtext(PG_FUNCTION_ARGS)
159159
{
160-
text*key=PG_GETARG_TEXT_P(0);
160+
text*key=PG_GETARG_TEXT_PP(0);
161161
Datumresult;
162162

163163
/*
164164
* Note: this is currently identical in behavior to hashvarlena, but keep
165165
* it as a separate function in case we someday want to do something
166166
* different in non-C locales.(See also hashbpchar, if so.)
167167
*/
168-
result=hash_any((unsignedchar*)VARDATA(key),
169-
VARSIZE(key)-VARHDRSZ);
168+
result=hash_any((unsignedchar*)VARDATA_ANY(key),
169+
VARSIZE_ANY_EXHDR(key));
170170

171171
/* Avoid leaking memory for toasted inputs */
172172
PG_FREE_IF_COPY(key,0);
@@ -181,11 +181,11 @@ hashtext(PG_FUNCTION_ARGS)
181181
Datum
182182
hashvarlena(PG_FUNCTION_ARGS)
183183
{
184-
structvarlena*key=PG_GETARG_VARLENA_P(0);
184+
structvarlena*key=PG_GETARG_VARLENA_PP(0);
185185
Datumresult;
186186

187-
result=hash_any((unsignedchar*)VARDATA(key),
188-
VARSIZE(key)-VARHDRSZ);
187+
result=hash_any((unsignedchar*)VARDATA_ANY(key),
188+
VARSIZE_ANY_EXHDR(key));
189189

190190
/* Avoid leaking memory for toasted inputs */
191191
PG_FREE_IF_COPY(key,0);

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

Lines changed: 42 additions & 41 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.69 2007/06/02 02:03:42 adunstan Exp $
14+
*$PostgreSQL: pgsql/src/backend/utils/adt/like.c,v 1.70 2007/09/21 22:52:52 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -135,6 +135,7 @@ Generic_Text_IC_like(text *str, text *pat)
135135
/* Force inputs to lower case to achieve case insensitivity */
136136
str=DatumGetTextP(DirectFunctionCall1(lower,PointerGetDatum(str)));
137137
pat=DatumGetTextP(DirectFunctionCall1(lower,PointerGetDatum(pat)));
138+
/* lower's result is never packed, so OK to use old macros here */
138139
s=VARDATA(str);
139140
slen= (VARSIZE(str)-VARHDRSZ);
140141
p=VARDATA(pat);
@@ -151,7 +152,7 @@ Datum
151152
namelike(PG_FUNCTION_ARGS)
152153
{
153154
Namestr=PG_GETARG_NAME(0);
154-
text*pat=PG_GETARG_TEXT_P(1);
155+
text*pat=PG_GETARG_TEXT_PP(1);
155156
boolresult;
156157
char*s,
157158
*p;
@@ -160,8 +161,8 @@ namelike(PG_FUNCTION_ARGS)
160161

161162
s=NameStr(*str);
162163
slen=strlen(s);
163-
p=VARDATA(pat);
164-
plen=(VARSIZE(pat)-VARHDRSZ);
164+
p=VARDATA_ANY(pat);
165+
plen=VARSIZE_ANY_EXHDR(pat);
165166

166167
result= (GenericMatchText(s,slen,p,plen)==LIKE_TRUE);
167168

@@ -172,7 +173,7 @@ Datum
172173
namenlike(PG_FUNCTION_ARGS)
173174
{
174175
Namestr=PG_GETARG_NAME(0);
175-
text*pat=PG_GETARG_TEXT_P(1);
176+
text*pat=PG_GETARG_TEXT_PP(1);
176177
boolresult;
177178
char*s,
178179
*p;
@@ -181,8 +182,8 @@ namenlike(PG_FUNCTION_ARGS)
181182

182183
s=NameStr(*str);
183184
slen=strlen(s);
184-
p=VARDATA(pat);
185-
plen=(VARSIZE(pat)-VARHDRSZ);
185+
p=VARDATA_ANY(pat);
186+
plen=VARSIZE_ANY_EXHDR(pat);
186187

187188
result= (GenericMatchText(s,slen,p,plen)!=LIKE_TRUE);
188189

@@ -192,18 +193,18 @@ namenlike(PG_FUNCTION_ARGS)
192193
Datum
193194
textlike(PG_FUNCTION_ARGS)
194195
{
195-
text*str=PG_GETARG_TEXT_P(0);
196-
text*pat=PG_GETARG_TEXT_P(1);
196+
text*str=PG_GETARG_TEXT_PP(0);
197+
text*pat=PG_GETARG_TEXT_PP(1);
197198
boolresult;
198199
char*s,
199200
*p;
200201
intslen,
201202
plen;
202203

203-
s=VARDATA(str);
204-
slen=(VARSIZE(str)-VARHDRSZ);
205-
p=VARDATA(pat);
206-
plen=(VARSIZE(pat)-VARHDRSZ);
204+
s=VARDATA_ANY(str);
205+
slen=VARSIZE_ANY_EXHDR(str);
206+
p=VARDATA_ANY(pat);
207+
plen=VARSIZE_ANY_EXHDR(pat);
207208

208209
result= (GenericMatchText(s,slen,p,plen)==LIKE_TRUE);
209210

@@ -213,18 +214,18 @@ textlike(PG_FUNCTION_ARGS)
213214
Datum
214215
textnlike(PG_FUNCTION_ARGS)
215216
{
216-
text*str=PG_GETARG_TEXT_P(0);
217-
text*pat=PG_GETARG_TEXT_P(1);
217+
text*str=PG_GETARG_TEXT_PP(0);
218+
text*pat=PG_GETARG_TEXT_PP(1);
218219
boolresult;
219220
char*s,
220221
*p;
221222
intslen,
222223
plen;
223224

224-
s=VARDATA(str);
225-
slen=(VARSIZE(str)-VARHDRSZ);
226-
p=VARDATA(pat);
227-
plen=(VARSIZE(pat)-VARHDRSZ);
225+
s=VARDATA_ANY(str);
226+
slen=VARSIZE_ANY_EXHDR(str);
227+
p=VARDATA_ANY(pat);
228+
plen=VARSIZE_ANY_EXHDR(pat);
228229

229230
result= (GenericMatchText(s,slen,p,plen)!=LIKE_TRUE);
230231

@@ -234,18 +235,18 @@ textnlike(PG_FUNCTION_ARGS)
234235
Datum
235236
bytealike(PG_FUNCTION_ARGS)
236237
{
237-
bytea*str=PG_GETARG_BYTEA_P(0);
238-
bytea*pat=PG_GETARG_BYTEA_P(1);
238+
bytea*str=PG_GETARG_BYTEA_PP(0);
239+
bytea*pat=PG_GETARG_BYTEA_PP(1);
239240
boolresult;
240241
char*s,
241242
*p;
242243
intslen,
243244
plen;
244245

245-
s=VARDATA(str);
246-
slen=(VARSIZE(str)-VARHDRSZ);
247-
p=VARDATA(pat);
248-
plen=(VARSIZE(pat)-VARHDRSZ);
246+
s=VARDATA_ANY(str);
247+
slen=VARSIZE_ANY_EXHDR(str);
248+
p=VARDATA_ANY(pat);
249+
plen=VARSIZE_ANY_EXHDR(pat);
249250

250251
result= (SB_MatchText(s,slen,p,plen)==LIKE_TRUE);
251252

@@ -255,18 +256,18 @@ bytealike(PG_FUNCTION_ARGS)
255256
Datum
256257
byteanlike(PG_FUNCTION_ARGS)
257258
{
258-
bytea*str=PG_GETARG_BYTEA_P(0);
259-
bytea*pat=PG_GETARG_BYTEA_P(1);
259+
bytea*str=PG_GETARG_BYTEA_PP(0);
260+
bytea*pat=PG_GETARG_BYTEA_PP(1);
260261
boolresult;
261262
char*s,
262263
*p;
263264
intslen,
264265
plen;
265266

266-
s=VARDATA(str);
267-
slen=(VARSIZE(str)-VARHDRSZ);
268-
p=VARDATA(pat);
269-
plen=(VARSIZE(pat)-VARHDRSZ);
267+
s=VARDATA_ANY(str);
268+
slen=VARSIZE_ANY_EXHDR(str);
269+
p=VARDATA_ANY(pat);
270+
plen=VARSIZE_ANY_EXHDR(pat);
270271

271272
result= (SB_MatchText(s,slen,p,plen)!=LIKE_TRUE);
272273

@@ -281,7 +282,7 @@ Datum
281282
nameiclike(PG_FUNCTION_ARGS)
282283
{
283284
Namestr=PG_GETARG_NAME(0);
284-
text*pat=PG_GETARG_TEXT_P(1);
285+
text*pat=PG_GETARG_TEXT_PP(1);
285286
boolresult;
286287
text*strtext;
287288

@@ -296,7 +297,7 @@ Datum
296297
nameicnlike(PG_FUNCTION_ARGS)
297298
{
298299
Namestr=PG_GETARG_NAME(0);
299-
text*pat=PG_GETARG_TEXT_P(1);
300+
text*pat=PG_GETARG_TEXT_PP(1);
300301
boolresult;
301302
text*strtext;
302303

@@ -310,8 +311,8 @@ nameicnlike(PG_FUNCTION_ARGS)
310311
Datum
311312
texticlike(PG_FUNCTION_ARGS)
312313
{
313-
text*str=PG_GETARG_TEXT_P(0);
314-
text*pat=PG_GETARG_TEXT_P(1);
314+
text*str=PG_GETARG_TEXT_PP(0);
315+
text*pat=PG_GETARG_TEXT_PP(1);
315316
boolresult;
316317

317318
result= (Generic_Text_IC_like(str,pat)==LIKE_TRUE);
@@ -322,8 +323,8 @@ texticlike(PG_FUNCTION_ARGS)
322323
Datum
323324
texticnlike(PG_FUNCTION_ARGS)
324325
{
325-
text*str=PG_GETARG_TEXT_P(0);
326-
text*pat=PG_GETARG_TEXT_P(1);
326+
text*str=PG_GETARG_TEXT_PP(0);
327+
text*pat=PG_GETARG_TEXT_PP(1);
327328
boolresult;
328329

329330
result= (Generic_Text_IC_like(str,pat)!=LIKE_TRUE);
@@ -338,8 +339,8 @@ texticnlike(PG_FUNCTION_ARGS)
338339
Datum
339340
like_escape(PG_FUNCTION_ARGS)
340341
{
341-
text*pat=PG_GETARG_TEXT_P(0);
342-
text*esc=PG_GETARG_TEXT_P(1);
342+
text*pat=PG_GETARG_TEXT_PP(0);
343+
text*esc=PG_GETARG_TEXT_PP(1);
343344
text*result;
344345

345346
if (pg_database_encoding_max_length()==1)
@@ -357,8 +358,8 @@ like_escape(PG_FUNCTION_ARGS)
357358
Datum
358359
like_escape_bytea(PG_FUNCTION_ARGS)
359360
{
360-
bytea*pat=PG_GETARG_BYTEA_P(0);
361-
bytea*esc=PG_GETARG_BYTEA_P(1);
361+
bytea*pat=PG_GETARG_BYTEA_PP(0);
362+
bytea*esc=PG_GETARG_BYTEA_PP(1);
362363
bytea*result=SB_do_like_escape((text*)pat, (text*)esc);
363364

364365
PG_RETURN_BYTEA_P((bytea*)result);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Copyright (c) 1996-2007, PostgreSQL Global Development Group
1818
*
1919
* IDENTIFICATION
20-
*$PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.16 2007/06/02 02:03:42 adunstan Exp $
20+
*$PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.17 2007/09/21 22:52:52 tgl Exp $
2121
*
2222
*-------------------------------------------------------------------------
2323
*/
@@ -242,10 +242,10 @@ do_like_escape(text *pat, text *esc)
242242
elen;
243243
boolafterescape;
244244

245-
p=VARDATA(pat);
246-
plen=(VARSIZE(pat)-VARHDRSZ);
247-
e=VARDATA(esc);
248-
elen=(VARSIZE(esc)-VARHDRSZ);
245+
p=VARDATA_ANY(pat);
246+
plen=VARSIZE_ANY_EXHDR(pat);
247+
e=VARDATA_ANY(esc);
248+
elen=VARSIZE_ANY_EXHDR(esc);
249249

250250
/*
251251
* Worst-case pattern growth is 2x --- unlikely, but it's hardly worth
@@ -279,14 +279,14 @@ do_like_escape(text *pat, text *esc)
279279
errmsg("invalid escape string"),
280280
errhint("Escape string must be empty or one character.")));
281281

282-
e=VARDATA(esc);
282+
e=VARDATA_ANY(esc);
283283

284284
/*
285285
* If specified escape is '\', just copy the pattern as-is.
286286
*/
287287
if (*e=='\\')
288288
{
289-
memcpy(result,pat,VARSIZE(pat));
289+
memcpy(result,pat,VARSIZE_ANY(pat));
290290
returnresult;
291291
}
292292

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp