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

Appearance settings

Commit f8942f4

Browse filesBrowse 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.) This prevents 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" typmod values too, though I think it probably doesn't matter anywhere else.
1 parent 190df8a commit f8942f4
Copy full SHA for f8942f4

File tree

Expand file treeCollapse file tree

10 files changed

+31
-26
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+31
-26
lines changed

‎src/backend/commands/tablecmds.c

Copy file name to clipboardExpand all lines: src/backend/commands/tablecmds.c
+7-4Lines 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-
Oid basetype = getBaseType(typeOid);
3182+
Oid baseTypeId;
3183+
int32 baseTypeMod;
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

Copy file name to clipboardExpand all lines: src/backend/executor/execQual.c
+2-2Lines 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

Copy file name to clipboardExpand all lines: src/backend/nodes/makefuncs.c
+6-5Lines 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(Oid consttype)
183+
makeNullConst(Oid consttype, int32 consttypmod)
183184
{
184185
int16 typLen;
185186
bool typByVal;
186187

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

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

Copy file name to clipboardExpand all lines: src/backend/optimizer/util/clauses.c
+3-3Lines 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
* AUTHOR DATE MAJOR 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

Copy file name to clipboardExpand all lines: src/backend/parser/parse_coerce.c
+2-2Lines 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

Copy file name to clipboardExpand all lines: src/backend/parser/parse_relation.c
+2-2Lines 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

Copy file name to clipboardExpand all lines: src/backend/parser/parse_target.c
+2-2Lines 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

Copy file name to clipboardExpand all lines: src/backend/rewrite/rewriteHandler.c
+2-2Lines 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

Copy file name to clipboardExpand all lines: src/backend/rewrite/rewriteManip.c
+3-2Lines 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-
return coerce_to_domain((Node *) makeNullConst(var->vartype),
899+
return coerce_to_domain((Node *) makeNullConst(var->vartype,
900+
var->vartypmod),
900901
InvalidOid, -1,
901902
var->vartype,
902903
COERCE_IMPLICIT_CAST,

‎src/include/nodes/makefuncs.h

Copy file name to clipboardExpand all lines: src/include/nodes/makefuncs.h
+2-2Lines 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
bool constisnull,
4646
bool constbyval);
4747

48-
extern Const *makeNullConst(Oid consttype);
48+
extern Const *makeNullConst(Oid consttype, int32 consttypmod);
4949

5050
extern Node *makeBoolConst(bool value, bool isnull);
5151

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.