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

Commit31bc839

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

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

‎src/backend/parser/gram.y

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13341,6 +13341,7 @@ makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
1334113341
x->args = args;
1334213342
/* xmloption, if relevant, must be filled in by caller*/
1334313343
/* type and typmod will be filled in during parse analysis*/
13344+
x->type = InvalidOid;/* marks the node as not analyzed*/
1334413345
x->location = location;
1334513346
return (Node *) x;
1334613347
}

‎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
@@ -1775,11 +1777,17 @@ transformArrayExpr(ParseState *pstate, A_ArrayExpr *a,
17751777
staticNode*
17761778
transformRowExpr(ParseState*pstate,RowExpr*r)
17771779
{
1778-
RowExpr*newr=makeNode(RowExpr);
1780+
RowExpr*newr;
17791781
charfname[16];
17801782
intfnum;
17811783
ListCell*lc;
17821784

1785+
/* If we already transformed this node, do nothing */
1786+
if (OidIsValid(r->row_typeid))
1787+
return (Node*)r;
1788+
1789+
newr=makeNode(RowExpr);
1790+
17831791
/* Transform the field expressions */
17841792
newr->args=transformExpressionList(pstate,r->args,pstate->p_expr_kind);
17851793

@@ -1880,16 +1888,23 @@ transformMinMaxExpr(ParseState *pstate, MinMaxExpr *m)
18801888
staticNode*
18811889
transformXmlExpr(ParseState*pstate,XmlExpr*x)
18821890
{
1883-
XmlExpr*newx=makeNode(XmlExpr);
1891+
XmlExpr*newx;
18841892
ListCell*lc;
18851893
inti;
18861894

1895+
/* If we already transformed this node, do nothing */
1896+
if (OidIsValid(x->type))
1897+
return (Node*)x;
1898+
1899+
newx=makeNode(XmlExpr);
18871900
newx->op=x->op;
18881901
if (x->name)
18891902
newx->name=map_sql_identifier_to_xml_name(x->name, false, false);
18901903
else
18911904
newx->name=NULL;
18921905
newx->xmloption=x->xmloption;
1906+
newx->type=XMLOID;/* this just marks the node as transformed */
1907+
newx->typmod=-1;
18931908
newx->location=x->location;
18941909

18951910
/*

‎src/include/nodes/primnodes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,8 @@ typedef struct MinMaxExpr
958958
*
959959
* Note: result type/typmod/collation are not stored, but can be deduced
960960
* from the XmlExprOp.The type/typmod fields are just used for display
961-
* purposes, and are NOT the true result type of the node.
961+
* purposes, and are NOT necessarily the true result type of the node.
962+
* (We also use type == InvalidOid to mark a not-yet-parse-analyzed XmlExpr.)
962963
*/
963964
typedefenumXmlExprOp
964965
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp