Skip to content

Commit 0f4ff46

Browse files
committed
Fix up the remaining places where the expression node structure would lose
available information about the typmod of an expression; namely, Const, ArrayRef, ArrayExpr, and EXPR and ARRAY SubLinks. In the ArrayExpr and SubLink cases it wasn't really the data structure's fault, but exprTypmod() being lazy. This seems like a good idea in view of the expected increase in typmod usage from Teodor's work to allow user-defined types to have typmods. In particular this responds to the concerns we had about eliminating the special-purpose hack that exprTypmod() used to have for BPCHAR Consts. We can now tell whether or not such a Const has been cast to a specific length, and report or display properly if so. initdb forced due to changes in stored rules.
1 parent 51d7741 commit 0f4ff46

File tree

21 files changed

+239
-117
lines changed

21 files changed

+239
-117
lines changed

src/backend/nodes/copyfuncs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.370 2007/03/13 00:33:40 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.371 2007/03/17 00:11:03 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -773,6 +773,7 @@ _copyConst(Const *from)
773773
Const *newnode = makeNode(Const);
774774

775775
COPY_SCALAR_FIELD(consttype);
776+
COPY_SCALAR_FIELD(consttypmod);
776777
COPY_SCALAR_FIELD(constlen);
777778

778779
if (from->constbyval || from->constisnull)
@@ -841,9 +842,9 @@ _copyArrayRef(ArrayRef *from)
841842
{
842843
ArrayRef *newnode = makeNode(ArrayRef);
843844

844-
COPY_SCALAR_FIELD(refrestype);
845845
COPY_SCALAR_FIELD(refarraytype);
846846
COPY_SCALAR_FIELD(refelemtype);
847+
COPY_SCALAR_FIELD(reftypmod);
847848
COPY_NODE_FIELD(refupperindexpr);
848849
COPY_NODE_FIELD(reflowerindexpr);
849850
COPY_NODE_FIELD(refexpr);

src/backend/nodes/equalfuncs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Portions Copyright (c) 1994, Regents of the University of California
1919
*
2020
* IDENTIFICATION
21-
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.301 2007/03/13 00:33:40 tgl Exp $
21+
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.302 2007/03/17 00:11:03 tgl Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -139,6 +139,7 @@ static bool
139139
_equalConst(Const *a, Const *b)
140140
{
141141
COMPARE_SCALAR_FIELD(consttype);
142+
COMPARE_SCALAR_FIELD(consttypmod);
142143
COMPARE_SCALAR_FIELD(constlen);
143144
COMPARE_SCALAR_FIELD(constisnull);
144145
COMPARE_SCALAR_FIELD(constbyval);
@@ -180,9 +181,9 @@ _equalAggref(Aggref *a, Aggref *b)
180181
static bool
181182
_equalArrayRef(ArrayRef *a, ArrayRef *b)
182183
{
183-
COMPARE_SCALAR_FIELD(refrestype);
184184
COMPARE_SCALAR_FIELD(refarraytype);
185185
COMPARE_SCALAR_FIELD(refelemtype);
186+
COMPARE_SCALAR_FIELD(reftypmod);
186187
COMPARE_NODE_FIELD(refupperindexpr);
187188
COMPARE_NODE_FIELD(reflowerindexpr);
188189
COMPARE_NODE_FIELD(refexpr);

src/backend/nodes/makefuncs.c

Lines changed: 8 additions & 2 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.54 2007/01/05 22:19:30 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.55 2007/03/17 00:11:03 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -140,6 +140,7 @@ flatCopyTargetEntry(TargetEntry *src_tle)
140140
*/
141141
Const *
142142
makeConst(Oid consttype,
143+
int32 consttypmod,
143144
int constlen,
144145
Datum constvalue,
145146
bool constisnull,
@@ -148,6 +149,7 @@ makeConst(Oid consttype,
148149
Const *cnst = makeNode(Const);
149150

150151
cnst->consttype = consttype;
152+
cnst->consttypmod = consttypmod;
151153
cnst->constlen = constlen;
152154
cnst->constvalue = constvalue;
153155
cnst->constisnull = constisnull;
@@ -159,6 +161,8 @@ makeConst(Oid consttype,
159161
/*
160162
* makeNullConst -
161163
* creates a Const node representing a NULL of the specified type
164+
*
165+
* Note: for all current uses, OK to set typmod of the Const to -1.
162166
*/
163167
Const *
164168
makeNullConst(Oid consttype)
@@ -168,6 +172,7 @@ makeNullConst(Oid consttype)
168172

169173
get_typlenbyval(consttype, &typLen, &typByVal);
170174
return makeConst(consttype,
175+
-1,
171176
(int) typLen,
172177
(Datum) 0,
173178
true,
@@ -182,7 +187,8 @@ Node *
182187
makeBoolConst(bool value, bool isnull)
183188
{
184189
/* note that pg_type.h hardwires size of bool as 1 ... duplicate it */
185-
return (Node *) makeConst(BOOLOID, 1, BoolGetDatum(value), isnull, true);
190+
return (Node *) makeConst(BOOLOID, -1, 1,
191+
BoolGetDatum(value), isnull, true);
186192
}
187193

188194
/*

src/backend/nodes/outfuncs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.303 2007/03/13 00:33:40 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.304 2007/03/17 00:11:03 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -685,6 +685,7 @@ _outConst(StringInfo str, Const *node)
685685
WRITE_NODE_TYPE("CONST");
686686

687687
WRITE_OID_FIELD(consttype);
688+
WRITE_INT_FIELD(consttypmod);
688689
WRITE_INT_FIELD(constlen);
689690
WRITE_BOOL_FIELD(constbyval);
690691
WRITE_BOOL_FIELD(constisnull);
@@ -725,9 +726,9 @@ _outArrayRef(StringInfo str, ArrayRef *node)
725726
{
726727
WRITE_NODE_TYPE("ARRAYREF");
727728

728-
WRITE_OID_FIELD(refrestype);
729729
WRITE_OID_FIELD(refarraytype);
730730
WRITE_OID_FIELD(refelemtype);
731+
WRITE_INT_FIELD(reftypmod);
731732
WRITE_NODE_FIELD(refupperindexpr);
732733
WRITE_NODE_FIELD(reflowerindexpr);
733734
WRITE_NODE_FIELD(refexpr);

src/backend/nodes/readfuncs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.203 2007/02/20 17:32:15 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.204 2007/03/17 00:11:04 tgl Exp $
1212
*
1313
* NOTES
1414
* Path and Plan nodes do not have any readfuncs support, because we
@@ -324,6 +324,7 @@ _readConst(void)
324324
READ_LOCALS(Const);
325325

326326
READ_OID_FIELD(consttype);
327+
READ_INT_FIELD(consttypmod);
327328
READ_INT_FIELD(constlen);
328329
READ_BOOL_FIELD(constbyval);
329330
READ_BOOL_FIELD(constisnull);
@@ -379,9 +380,9 @@ _readArrayRef(void)
379380
{
380381
READ_LOCALS(ArrayRef);
381382

382-
READ_OID_FIELD(refrestype);
383383
READ_OID_FIELD(refarraytype);
384384
READ_OID_FIELD(refelemtype);
385+
READ_INT_FIELD(reftypmod);
385386
READ_NODE_FIELD(refupperindexpr);
386387
READ_NODE_FIELD(reflowerindexpr);
387388
READ_NODE_FIELD(refexpr);

src/backend/optimizer/path/indxpath.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.216 2007/01/20 20:45:39 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.217 2007/03/17 00:11:04 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -2628,7 +2628,7 @@ network_prefix_quals(Node *leftop, Oid expr_op, Oid opfamily, Datum rightop)
26282628

26292629
expr = make_opclause(opr1oid, BOOLOID, false,
26302630
(Expr *) leftop,
2631-
(Expr *) makeConst(datatype, -1, opr1right,
2631+
(Expr *) makeConst(datatype, -1, -1, opr1right,
26322632
false, false));
26332633
result = list_make1(make_restrictinfo(expr, true, false, false, NULL));
26342634

@@ -2643,7 +2643,7 @@ network_prefix_quals(Node *leftop, Oid expr_op, Oid opfamily, Datum rightop)
26432643

26442644
expr = make_opclause(opr2oid, BOOLOID, false,
26452645
(Expr *) leftop,
2646-
(Expr *) makeConst(datatype, -1, opr2right,
2646+
(Expr *) makeConst(datatype, -1, -1, opr2right,
26472647
false, false));
26482648
result = lappend(result,
26492649
make_restrictinfo(expr, true, false, false, NULL));
@@ -2683,6 +2683,7 @@ string_to_const(const char *str, Oid datatype)
26832683
{
26842684
Datum conval = string_to_datum(str, datatype);
26852685

2686-
return makeConst(datatype, ((datatype == NAMEOID) ? NAMEDATALEN : -1),
2686+
return makeConst(datatype, -1,
2687+
((datatype == NAMEOID) ? NAMEDATALEN : -1),
26872688
conval, false, false);
26882689
}

src/backend/optimizer/plan/planagg.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/optimizer/plan/planagg.c,v 1.29 2007/02/22 22:00:24 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.30 2007/03/17 00:11:04 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -477,7 +477,7 @@ make_agg_subplan(PlannerInfo *root, MinMaxAggInfo *info)
477477

478478
/* set up LIMIT 1 */
479479
subparse->limitOffset = NULL;
480-
subparse->limitCount = (Node *) makeConst(INT8OID, sizeof(int64),
480+
subparse->limitCount = (Node *) makeConst(INT8OID, -1, sizeof(int64),
481481
Int64GetDatum(1),
482482
false, false /* not by val */ );
483483

src/backend/optimizer/prep/preptlist.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Portions Copyright (c) 1994, Regents of the University of California
1717
*
1818
* IDENTIFICATION
19-
* $PostgreSQL: pgsql/src/backend/optimizer/prep/preptlist.c,v 1.86 2007/02/19 07:03:30 tgl Exp $
19+
* $PostgreSQL: pgsql/src/backend/optimizer/prep/preptlist.c,v 1.87 2007/03/17 00:11:04 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -281,6 +281,7 @@ expand_targetlist(List *tlist, int command_type,
281281
if (!att_tup->attisdropped)
282282
{
283283
new_expr = (Node *) makeConst(atttype,
284+
-1,
284285
att_tup->attlen,
285286
(Datum) 0,
286287
true, /* isnull */
@@ -296,6 +297,7 @@ expand_targetlist(List *tlist, int command_type,
296297
{
297298
/* Insert NULL for dropped column */
298299
new_expr = (Node *) makeConst(INT4OID,
300+
-1,
299301
sizeof(int32),
300302
(Datum) 0,
301303
true, /* isnull */
@@ -315,6 +317,7 @@ expand_targetlist(List *tlist, int command_type,
315317
{
316318
/* Insert NULL for dropped column */
317319
new_expr = (Node *) makeConst(INT4OID,
320+
-1,
318321
sizeof(int32),
319322
(Datum) 0,
320323
true, /* isnull */

src/backend/optimizer/prep/prepunion.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.139 2007/02/22 22:00:24 tgl Exp $
25+
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.140 2007/03/17 00:11:04 tgl Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -545,6 +545,7 @@ generate_setop_tlist(List *colTypes, int flag,
545545
/* Add a resjunk flag column */
546546
/* flag value is the given constant */
547547
expr = (Node *) makeConst(INT4OID,
548+
-1,
548549
sizeof(int4),
549550
Int32GetDatum(flag),
550551
false,

0 commit comments

Comments
 (0)