summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-12-23 14:07:36 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2012-12-23 14:07:36 -0500
commit628ea7ea51e046bade9ce7f15dc9c41118e29f13 (patch)
tree498d460f6ca04d23a76f651928c05e04a7f3a6f9
parent14aa55df29ea69e453be4c46f8546d49365fc06b (diff)
downloadpostgresql-628ea7ea51e046bade9ce7f15dc9c41118e29f13.tar.gz
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
-rw-r--r--src/backend/parser/gram.y1
-rw-r--r--src/backend/parser/parse_expr.c19
-rw-r--r--src/include/nodes/primnodes.h3
3 files changed, 20 insertions, 3 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 62cff8a7de..d0d9492bb1 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -12728,6 +12728,7 @@ makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
x->args = args;
/* xmloption, if relevant, must be filled in by caller */
/* type and typmod will be filled in during parse analysis */
+ x->type = InvalidOid; /* marks the node as not analyzed */
x->location = location;
return (Node *) x;
}
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 75236c76a1..228bbfc9b0 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -91,6 +91,8 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
* function argument to the required type (via coerce_type())
* can apply transformExpr to an already-transformed subexpression.
* An example here is "SELECT count(*) + 1.0 FROM table".
+ * 3. CREATE TABLE t1 (LIKE t2 INCLUDING INDEXES) can pass in
+ * already-transformed index expressions.
* While it might be possible to eliminate these cases, the path of
* least resistance so far has been to ensure that transformExpr() does
* no damage if applied to an already-transformed tree. This is pretty
@@ -1691,7 +1693,13 @@ transformArrayExpr(ParseState *pstate, A_ArrayExpr *a,
static Node *
transformRowExpr(ParseState *pstate, RowExpr *r)
{
- RowExpr *newr = makeNode(RowExpr);
+ RowExpr *newr;
+
+ /* If we already transformed this node, do nothing */
+ if (OidIsValid(r->row_typeid))
+ return (Node *) r;
+
+ newr = makeNode(RowExpr);
/* Transform the field expressions */
newr->args = transformExpressionList(pstate, r->args);
@@ -1784,16 +1792,23 @@ transformMinMaxExpr(ParseState *pstate, MinMaxExpr *m)
static Node *
transformXmlExpr(ParseState *pstate, XmlExpr *x)
{
- XmlExpr *newx = makeNode(XmlExpr);
+ XmlExpr *newx;
ListCell *lc;
int i;
+ /* If we already transformed this node, do nothing */
+ if (OidIsValid(x->type))
+ return (Node *) x;
+
+ newx = makeNode(XmlExpr);
newx->op = x->op;
if (x->name)
newx->name = map_sql_identifier_to_xml_name(x->name, false, false);
else
newx->name = NULL;
newx->xmloption = x->xmloption;
+ newx->type = XMLOID; /* this just marks the node as transformed */
+ newx->typmod = -1;
newx->location = x->location;
/*
diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h
index f1e20ef937..5815139447 100644
--- a/src/include/nodes/primnodes.h
+++ b/src/include/nodes/primnodes.h
@@ -944,7 +944,8 @@ typedef struct MinMaxExpr
*
* Note: result type/typmod/collation are not stored, but can be deduced
* from the XmlExprOp. The type/typmod fields are just used for display
- * purposes, and are NOT the true result type of the node.
+ * purposes, and are NOT necessarily the true result type of the node.
+ * (We also use type == InvalidOid to mark a not-yet-parse-analyzed XmlExpr.)
*/
typedef enum XmlExprOp
{