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

Commitbfa4440

Browse files
committed
Pass collation to makeConst() instead of looking it up internally.
In nearly all cases, the caller already knows the correct collation, andin a number of places, the value the caller has handy is more correct thanthe default for the type would be. (In particular, this patch makes itsignificantly less likely that eval_const_expressions will result inchanging the exposed collation of an expression.) So an internal lookupis both expensive and wrong.
1 parentc8e9935 commitbfa4440

File tree

18 files changed

+165
-56
lines changed

18 files changed

+165
-56
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4337,10 +4337,12 @@ ATExecAddColumn(AlteredTableInfo *tab, Relation rel,
43374337
{
43384338
OidbaseTypeId;
43394339
int32baseTypeMod;
4340+
OidbaseTypeColl;
43404341

43414342
baseTypeMod=typmod;
43424343
baseTypeId=getBaseTypeAndTypmod(typeOid,&baseTypeMod);
4343-
defval= (Expr*)makeNullConst(baseTypeId,baseTypeMod);
4344+
baseTypeColl=get_typcollation(baseTypeId);
4345+
defval= (Expr*)makeNullConst(baseTypeId,baseTypeMod,baseTypeColl);
43444346
defval= (Expr*)coerce_to_target_type(NULL,
43454347
(Node*)defval,
43464348
baseTypeId,

‎src/backend/executor/execQual.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4653,7 +4653,7 @@ ExecInitExpr(Expr *node, PlanState *parent)
46534653
* don't really care what type of NULL it is, so
46544654
* always make an int4 NULL.
46554655
*/
4656-
e= (Expr*)makeNullConst(INT4OID,-1);
4656+
e= (Expr*)makeNullConst(INT4OID,-1,InvalidOid);
46574657
}
46584658
estate=ExecInitExpr(e,parent);
46594659
outlist=lappend(outlist,estate);

‎src/backend/executor/functions.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,7 @@ check_sql_fn_retval(Oid func_id, Oid rettype, List *queryTreeList,
15011501
/* The type of the null we insert isn't important */
15021502
null_expr= (Expr*)makeConst(INT4OID,
15031503
-1,
1504+
InvalidOid,
15041505
sizeof(int32),
15051506
(Datum)0,
15061507
true,/* isnull */
@@ -1562,6 +1563,7 @@ check_sql_fn_retval(Oid func_id, Oid rettype, List *queryTreeList,
15621563
/* The type of the null we insert isn't important */
15631564
null_expr= (Expr*)makeConst(INT4OID,
15641565
-1,
1566+
InvalidOid,
15651567
sizeof(int32),
15661568
(Datum)0,
15671569
true,/* isnull */

‎src/backend/nodes/makefuncs.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ makeFromExpr(List *fromlist, Node *quals)
271271
Const*
272272
makeConst(Oidconsttype,
273273
int32consttypmod,
274+
Oidconstcollid,
274275
intconstlen,
275276
Datumconstvalue,
276277
boolconstisnull,
@@ -280,7 +281,7 @@ makeConst(Oid consttype,
280281

281282
cnst->consttype=consttype;
282283
cnst->consttypmod=consttypmod;
283-
cnst->constcollid=get_typcollation(consttype);
284+
cnst->constcollid=constcollid;
284285
cnst->constlen=constlen;
285286
cnst->constvalue=constvalue;
286287
cnst->constisnull=constisnull;
@@ -298,14 +299,15 @@ makeConst(Oid consttype,
298299
* storage properties.
299300
*/
300301
Const*
301-
makeNullConst(Oidconsttype,int32consttypmod)
302+
makeNullConst(Oidconsttype,int32consttypmod,Oidconstcollid)
302303
{
303304
int16typLen;
304305
booltypByVal;
305306

306307
get_typlenbyval(consttype,&typLen,&typByVal);
307308
returnmakeConst(consttype,
308309
consttypmod,
310+
constcollid,
309311
(int)typLen,
310312
(Datum)0,
311313
true,
@@ -320,7 +322,7 @@ Node *
320322
makeBoolConst(boolvalue,boolisnull)
321323
{
322324
/* note that pg_type.h hardwires size of bool as 1 ... duplicate it */
323-
return (Node*)makeConst(BOOLOID,-1,1,
325+
return (Node*)makeConst(BOOLOID,-1,InvalidOid,1,
324326
BoolGetDatum(value),isnull, true);
325327
}
326328

‎src/backend/optimizer/path/indxpath.c

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include"access/skey.h"
2121
#include"catalog/pg_am.h"
22+
#include"catalog/pg_collation.h"
2223
#include"catalog/pg_operator.h"
2324
#include"catalog/pg_opfamily.h"
2425
#include"catalog/pg_type.h"
@@ -3233,7 +3234,9 @@ network_prefix_quals(Node *leftop, Oid expr_op, Oid opfamily, Datum rightop)
32333234

32343235
expr=make_opclause(opr1oid,BOOLOID, false,
32353236
(Expr*)leftop,
3236-
(Expr*)makeConst(datatype,-1,-1,opr1right,
3237+
(Expr*)makeConst(datatype,-1,
3238+
InvalidOid,/* not collatable */
3239+
-1,opr1right,
32373240
false, false),
32383241
InvalidOid,InvalidOid);
32393242
result=list_make1(make_simple_restrictinfo(expr));
@@ -3249,7 +3252,9 @@ network_prefix_quals(Node *leftop, Oid expr_op, Oid opfamily, Datum rightop)
32493252

32503253
expr=make_opclause(opr2oid,BOOLOID, false,
32513254
(Expr*)leftop,
3252-
(Expr*)makeConst(datatype,-1,-1,opr2right,
3255+
(Expr*)makeConst(datatype,-1,
3256+
InvalidOid,/* not collatable */
3257+
-1,opr2right,
32533258
false, false),
32543259
InvalidOid,InvalidOid);
32553260
result=lappend(result,make_simple_restrictinfo(expr));
@@ -3288,8 +3293,38 @@ static Const *
32883293
string_to_const(constchar*str,Oiddatatype)
32893294
{
32903295
Datumconval=string_to_datum(str,datatype);
3296+
Oidcollation;
3297+
intconstlen;
32913298

3292-
returnmakeConst(datatype,-1,
3293-
((datatype==NAMEOID) ?NAMEDATALEN :-1),
3299+
/*
3300+
* We only need to support a few datatypes here, so hard-wire properties
3301+
* instead of incurring the expense of catalog lookups.
3302+
*/
3303+
switch (datatype)
3304+
{
3305+
caseTEXTOID:
3306+
caseVARCHAROID:
3307+
caseBPCHAROID:
3308+
collation=DEFAULT_COLLATION_OID;
3309+
constlen=-1;
3310+
break;
3311+
3312+
caseNAMEOID:
3313+
collation=InvalidOid;
3314+
constlen=NAMEDATALEN;
3315+
break;
3316+
3317+
caseBYTEAOID:
3318+
collation=InvalidOid;
3319+
constlen=-1;
3320+
break;
3321+
3322+
default:
3323+
elog(ERROR,"unexpected datatype in string_to_const: %u",
3324+
datatype);
3325+
returnNULL;
3326+
}
3327+
3328+
returnmakeConst(datatype,-1,collation,constlen,
32943329
conval, false, false);
32953330
}

‎src/backend/optimizer/plan/planagg.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ build_minmax_path(PlannerInfo *root, MinMaxAggInfo *mminfo,
429429

430430
/* set up expressions for LIMIT 1 */
431431
parse->limitOffset=NULL;
432-
parse->limitCount= (Node*)makeConst(INT8OID,-1,sizeof(int64),
432+
parse->limitCount= (Node*)makeConst(INT8OID,-1,InvalidOid,
433+
sizeof(int64),
433434
Int64GetDatum(1), false,
434435
FLOAT8PASSBYVAL);
435436

‎src/backend/optimizer/prep/preptlist.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ expand_targetlist(List *tlist, int command_type,
269269
{
270270
new_expr= (Node*)makeConst(atttype,
271271
-1,
272+
attcollation,
272273
att_tup->attlen,
273274
(Datum)0,
274275
true,/* isnull */
@@ -286,6 +287,7 @@ expand_targetlist(List *tlist, int command_type,
286287
/* Insert NULL for dropped column */
287288
new_expr= (Node*)makeConst(INT4OID,
288289
-1,
290+
InvalidOid,
289291
sizeof(int32),
290292
(Datum)0,
291293
true,/* isnull */
@@ -307,6 +309,7 @@ expand_targetlist(List *tlist, int command_type,
307309
/* Insert NULL for dropped column */
308310
new_expr= (Node*)makeConst(INT4OID,
309311
-1,
312+
InvalidOid,
310313
sizeof(int32),
311314
(Datum)0,
312315
true,/* isnull */

‎src/backend/optimizer/prep/prepunion.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ generate_setop_tlist(List *colTypes, int flag,
910910
/* flag value is the given constant */
911911
expr= (Node*)makeConst(INT4OID,
912912
-1,
913+
InvalidOid,
913914
sizeof(int4),
914915
Int32GetDatum(flag),
915916
false,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp