8000 Prevent failure when RowExpr or XmlExpr is parse-analyzed twice. · mwarnock/postgres@4297f17 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4297f17

Browse files
committed
Prevent failure when RowExpr or XmlExpr is parse-analyzed twice.
transformExpr() is required to cope with already-transformed expression trees, for various ugly-but-not-quite-worth-cleaning-up reasons. However, some of its newer subroutines hadn't gotten the memo. This accounts for bug #7763 from Norbert Buchmuller: transformRowExpr() was overwriting the previously determined type of a RowExpr during CREATE TABLE LIKE INCLUDING INDEXES. Additional investigation showed that transformXmlExpr had the same kind of problem, but all the other cases seem to be safe. Andres Freund and Tom Lane
1 parent 3fd0393 commit 4297f17

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/backend/parser/gram.y

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9817,6 +9817,9 @@ makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args)
98179817
x->named_args = named_args;
98189818
x->arg_names = NIL;
98199819
x->args = args;
9820+
/* xmloption, if relevant, must be filled in by caller */
9821+
/* type and typmod will be filled in during parse analysis */
9822+
x->type = InvalidOid; /* marks the node as not analyzed */
98209823
return (Node *) x;
98219824
}
98229825

src/backend/parser/parse_expr.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
9292
* function argument to the required type (via coerce_type())
9393
* can apply transformExpr to an already-transformed subexpression.
9494
* An example here is "SELECT count(*) + 1.0 FROM table".
95+
* 3. CREATE TABLE t1 (LIKE t2 INCLUDING INDEXES) can pass in
96+
* already-transformed index expressions.
9597
* While it might be possible to eliminate these cases, the path of
9698
* least resistance so far has been to ensure that transformExpr() does
9799
* no damage if applied to an already-transformed tree. This is pretty
@@ -1341,7 +1343,13 @@ transformArrayExpr(ParseState *pstate, ArrayExpr *a)
13411343
static Node *
13421344
transformRowExpr(ParseState *pstate, RowExpr *r)
13431345
{
1344-
RowExpr *newr = makeNode(RowExpr);
1346+
RowExpr *newr;
1347+
1348+
/* If we already transformed this node, do nothing */
1349+
if (OidIsValid(r->row_typeid))
1350+
return (Node *) r;
1351+
1352+
newr = makeNode(RowExpr);
13451353

13461354
/* Transform the field expressions */
13471355
newr->args = transformExpressionList(pstate, r->args);
@@ -1431,15 +1439,22 @@ transformMinMaxExpr(ParseState *pstate, MinMaxExpr *m)
14311439
static Node *
14321440
transformXmlExpr(ParseState *pstate, XmlExpr *x)
14331441
{
1434-
XmlExpr *newx = makeNode(XmlExpr);
1442+
XmlExpr *newx;
14351443
ListCell *lc;
14361444
int i;
14371445

1446+
/* If we already transformed this node, do nothing */
1447+
if (OidIsValid(x->type))
1448+
return (Node *) x;
1449+
1450+
newx = makeNode(XmlExpr);
14381451
newx->op = x->op;
14391452
if (x->name)
14401453
newx->name = map_sql_identifier_to_xml_name(x->name, false, false);
14411454
else
14421455
newx->name = NULL;
1456+
newx->type = XMLOID; /* this just marks the node as transformed */
1457+
newx->typmod = -1;
14431458

14441459
/*
14 3C3F 451460
* gram.y built the named args as a list of ResTarget. Transform each,

0 commit comments

Comments
 (0)
0