aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/nodes/copyfuncs.c1
-rw-r--r--src/backend/nodes/equalfuncs.c1
-rw-r--r--src/backend/nodes/outfuncs.c1
-rw-r--r--src/backend/parser/gram.y1
-rw-r--r--src/backend/parser/parse_utilcmd.c14
5 files changed, 15 insertions, 3 deletions
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index b4a597bb83c..a0ef3ff1407 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -3368,6 +3368,7 @@ _copyTableLikeClause(const TableLikeClause *from)
COPY_NODE_FIELD(relation);
COPY_SCALAR_FIELD(options);
+ COPY_SCALAR_FIELD(relationOid);
return newnode;
}
diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c
index 4f2ebe5118e..88e17a3a604 100644
--- a/src/backend/nodes/equalfuncs.c
+++ b/src/backend/nodes/equalfuncs.c
@@ -1252,6 +1252,7 @@ _equalTableLikeClause(const TableLikeClause *a, const TableLikeClause *b)
{
COMPARE_NODE_FIELD(relation);
COMPARE_SCALAR_FIELD(options);
+ COMPARE_SCALAR_FIELD(relationOid);
return true;
}
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index fc75384c07b..4a0e461d366 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -2746,6 +2746,7 @@ _outTableLikeClause(StringInfo str, const TableLikeClause *node)
WRITE_NODE_FIELD(relation);
WRITE_UINT_FIELD(options);
+ WRITE_OID_FIELD(relationOid);
}
static void
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 32797728d2e..9de9dbd8a8a 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -3595,6 +3595,7 @@ TableLikeClause:
TableLikeClause *n = makeNode(TableLikeClause);
n->relation = $2;
n->options = $3;
+ n->relationOid = InvalidOid;
$$ = (Node *)n;
}
;
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index d3ef6f4ab58..577fe1e752e 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -1091,14 +1091,18 @@ transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_cla
* we don't yet know what column numbers the copied columns will have in
* the finished table. If any of those options are specified, add the
* LIKE clause to cxt->likeclauses so that expandTableLikeClause will be
- * called after we do know that.
+ * called after we do know that. Also, remember the relation OID so that
+ * expandTableLikeClause is certain to open the same table.
*/
if (table_like_clause->options &
(CREATE_TABLE_LIKE_DEFAULTS |
CREATE_TABLE_LIKE_GENERATED |
CREATE_TABLE_LIKE_CONSTRAINTS |
CREATE_TABLE_LIKE_INDEXES))
+ {
+ table_like_clause->relationOid = RelationGetRelid(relation);
cxt->likeclauses = lappend(cxt->likeclauses, table_like_clause);
+ }
/*
* We may copy extended statistics if requested, since the representation
@@ -1171,9 +1175,13 @@ expandTableLikeClause(RangeVar *heapRel, TableLikeClause *table_like_clause)
* Open the relation referenced by the LIKE clause. We should still have
* the table lock obtained by transformTableLikeClause (and this'll throw
* an assertion failure if not). Hence, no need to recheck privileges
- * etc.
+ * etc. We must open the rel by OID not name, to be sure we get the same
+ * table.
*/
- relation = relation_openrv(table_like_clause->relation, NoLock);
+ if (!OidIsValid(table_like_clause->relationOid))
+ elog(ERROR, "expandTableLikeClause called on untransformed LIKE clause");
+
+ relation = relation_open(table_like_clause->relationOid, NoLock);
tupleDesc = RelationGetDescr(relation);
constr = tupleDesc->constr;