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

Commitf8942f4

Browse files
committed
Make eval_const_expressions() preserve typmod when simplifying something like
null::char(3) to a simple Const node. (It already worked for non-null values,but not when we skipped evaluation of a strict coercion function.) Thisprevents loss of typmod knowledge in situations such as exhibited in bug#3598. Unfortunately there seems no good way to fix that bug in 8.1 and 8.2,because they simply don't carry a typmod for a plain Const node.In passing I made all the other callers of makeNullConst supply "real" typmodvalues too, though I think it probably doesn't matter anywhere else.
1 parent190df8a commitf8942f4

File tree

10 files changed

+31
-26
lines changed

10 files changed

+31
-26
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.231 2007/08/21 01:11:14 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.232 2007/09/06 17:31:58 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3179,12 +3179,15 @@ ATExecAddColumn(AlteredTableInfo *tab, Relation rel,
31793179

31803180
if (!defval&&GetDomainConstraints(typeOid)!=NIL)
31813181
{
3182-
Oidbasetype=getBaseType(typeOid);
3182+
OidbaseTypeId;
3183+
int32baseTypeMod;
31833184

3184-
defval= (Expr*)makeNullConst(basetype);
3185+
baseTypeMod=typmod;
3186+
baseTypeId=getBaseTypeAndTypmod(typeOid,&baseTypeMod);
3187+
defval= (Expr*)makeNullConst(baseTypeId,baseTypeMod);
31853188
defval= (Expr*)coerce_to_target_type(NULL,
31863189
(Node*)defval,
3187-
basetype,
3190+
baseTypeId,
31883191
typeOid,
31893192
typmod,
31903193
COERCION_ASSIGNMENT,

‎src/backend/executor/execQual.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.221 2007/08/31 18:33:40 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.222 2007/09/06 17:31:58 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -4159,7 +4159,7 @@ ExecInitExpr(Expr *node, PlanState *parent)
41594159
* don't really care what type of NULL it is, so
41604160
* always make an int4 NULL.
41614161
*/
4162-
e= (Expr*)makeNullConst(INT4OID);
4162+
e= (Expr*)makeNullConst(INT4OID,-1);
41634163
}
41644164
estate=ExecInitExpr(e,parent);
41654165
outlist=lappend(outlist,estate);

‎src/backend/nodes/makefuncs.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.56 2007/06/23 22:12:50 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.57 2007/09/06 17:31:58 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -174,19 +174,20 @@ makeConst(Oid consttype,
174174

175175
/*
176176
* makeNullConst -
177-
* creates a Const node representing a NULL of the specified type
177+
* creates a Const node representing a NULL of the specified type/typmod
178178
*
179-
* Note: for all current uses, OK to set typmod of the Const to -1.
179+
* This is a convenience routine that just saves a lookup of the type's
180+
* storage properties.
180181
*/
181182
Const*
182-
makeNullConst(Oidconsttype)
183+
makeNullConst(Oidconsttype,int32consttypmod)
183184
{
184185
int16typLen;
185186
booltypByVal;
186187

187188
get_typlenbyval(consttype,&typLen,&typByVal);
188189
returnmakeConst(consttype,
189-
-1,
190+
consttypmod,
190191
(int)typLen,
191192
(Datum)0,
192193
true,

‎src/backend/optimizer/util/clauses.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.248 2007/09/03 00:39:15 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.249 2007/09/06 17:31:58 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHORDATEMAJOR EVENT
@@ -2265,7 +2265,7 @@ eval_const_expressions_mutator(Node *node,
22652265

22662266
/* If all the arguments were constant null, the result is just null */
22672267
if (newargs==NIL)
2268-
return (Node*)makeNullConst(coalesceexpr->coalescetype);
2268+
return (Node*)makeNullConst(coalesceexpr->coalescetype,-1);
22692269

22702270
newcoalesce=makeNode(CoalesceExpr);
22712271
newcoalesce->coalescetype=coalesceexpr->coalescetype;
@@ -2833,7 +2833,7 @@ evaluate_function(Oid funcid, Oid result_type, int32 result_typmod, List *args,
28332833
* function is not otherwise immutable.
28342834
*/
28352835
if (funcform->proisstrict&&has_null_input)
2836-
return (Expr*)makeNullConst(result_type);
2836+
return (Expr*)makeNullConst(result_type,result_typmod);
28372837

28382838
/*
28392839
* Otherwise, can simplify only if all inputs are constants. (For a

‎src/backend/parser/parse_coerce.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.156 2007/08/21 01:11:15 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.157 2007/09/06 17:31:58 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -816,7 +816,7 @@ coerce_record_to_complex(ParseState *pstate, Node *node,
816816
* can't use atttypid here, but it doesn't really matter what type
817817
* the Const claims to be.
818818
*/
819-
newargs=lappend(newargs,makeNullConst(INT4OID));
819+
newargs=lappend(newargs,makeNullConst(INT4OID,-1));
820820
continue;
821821
}
822822

‎src/backend/parser/parse_relation.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.127 2007/01/05 22:19:34 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.128 2007/09/06 17:31:58 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1448,7 +1448,7 @@ expandTupleDesc(TupleDesc tupdesc, Alias *eref,
14481448
* can't use atttypid here, but it doesn't really matter
14491449
* what type the Const claims to be.
14501450
*/
1451-
*colvars=lappend(*colvars,makeNullConst(INT4OID));
1451+
*colvars=lappend(*colvars,makeNullConst(INT4OID,-1));
14521452
}
14531453
}
14541454
continue;

‎src/backend/parser/parse_target.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.154 2007/02/03 14:06:54 petere Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.155 2007/09/06 17:31:58 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -393,7 +393,7 @@ transformAssignedExpr(ParseState *pstate,
393393
* is not really a source value to work with. Insert a NULL
394394
* constant as the source value.
395395
*/
396-
colVar= (Node*)makeNullConst(attrtype);
396+
colVar= (Node*)makeNullConst(attrtype,attrtypmod);
397397
}
398398
else
399399
{

‎src/backend/rewrite/rewriteHandler.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.173 2007/03/19 23:38:29 wieck Exp $
10+
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.174 2007/09/06 17:31:58 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -193,7 +193,7 @@ AcquireRewriteLocks(Query *parsetree)
193193
* now-dropped type OID, but it doesn't really
194194
* matter what type the Const claims to be.
195195
*/
196-
aliasvar= (Var*)makeNullConst(INT4OID);
196+
aliasvar= (Var*)makeNullConst(INT4OID,-1);
197197
}
198198
}
199199
newaliasvars=lappend(newaliasvars,aliasvar);

‎src/backend/rewrite/rewriteManip.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteManip.c,v 1.104 2007/06/11 01:16:25 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteManip.c,v 1.105 2007/09/06 17:31:58 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -896,7 +896,8 @@ resolve_one_var(Var *var, ResolveNew_context *context)
896896
{
897897
/* Otherwise replace unmatched var with a null */
898898
/* need coerce_to_domain in case of NOT NULL domain constraint */
899-
returncoerce_to_domain((Node*)makeNullConst(var->vartype),
899+
returncoerce_to_domain((Node*)makeNullConst(var->vartype,
900+
var->vartypmod),
900901
InvalidOid,-1,
901902
var->vartype,
902903
COERCE_IMPLICIT_CAST,

‎src/include/nodes/makefuncs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/nodes/makefuncs.h,v 1.59 2007/06/23 22:12:52 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/nodes/makefuncs.h,v 1.60 2007/09/06 17:31:58 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -45,7 +45,7 @@ extern Const *makeConst(Oid consttype,
4545
boolconstisnull,
4646
boolconstbyval);
4747

48-
externConst*makeNullConst(Oidconsttype);
48+
externConst*makeNullConst(Oidconsttype,int32consttypmod);
4949

5050
externNode*makeBoolConst(boolvalue,boolisnull);
5151

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp