aboutsummaryrefslogtreecommitdiff
path: root/src/backend/nodes
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-12-01 14:02:28 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2020-12-01 14:02:28 -0500
commit28bb8c496691e0fb60f49eac08b4dc1d8bdd6b4a (patch)
tree3710e5119c757d8019a6eaadab713ce7da826c84 /src/backend/nodes
parent49aaabdf8d0b85cbf19537bb8bc12856f2e9dc4d (diff)
downloadpostgresql-28bb8c496691e0fb60f49eac08b4dc1d8bdd6b4a.tar.gz
postgresql-28bb8c496691e0fb60f49eac08b4dc1d8bdd6b4a.zip
Ensure that expandTableLikeClause() re-examines the same table.
As it stood, expandTableLikeClause() re-did the same relation_openrv call that transformTableLikeClause() had done. However there are scenarios where this would not find the same table as expected. We hold lock on the LIKE source table, so it can't be renamed or dropped, but another table could appear before it in the search path. This explains the odd behavior reported in bug #16758 when cloning a table as a temp table of the same name. This case worked as expected before commit 502898192 introduced the need to open the source table twice, so we should fix it. To make really sure we get the same table, let's re-open it by OID not name. That requires adding an OID field to struct TableLikeClause, which is a little nervous-making from an ABI standpoint, but as long as it's at the end I don't think there's any serious risk. Per bug #16758 from Marc Boeren. Like the previous patch, back-patch to all supported branches. Discussion: https://postgr.es/m/16758-840e84a6cfab276d@postgresql.org
Diffstat (limited to 'src/backend/nodes')
-rw-r--r--src/backend/nodes/copyfuncs.c1
-rw-r--r--src/backend/nodes/equalfuncs.c1
-rw-r--r--src/backend/nodes/outfuncs.c1
3 files changed, 3 insertions, 0 deletions
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index d2fc5dc8dce..a38d6e4db15 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -3356,6 +3356,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 88ed8168081..cf5238e9e08 100644
--- a/src/backend/nodes/equalfuncs.c
+++ b/src/backend/nodes/equalfuncs.c
@@ -1249,6 +1249,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 f5d786d79ad..fcc0fbd703e 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -2835,6 +2835,7 @@ _outTableLikeClause(StringInfo str, const TableLikeClause *node)
WRITE_NODE_FIELD(relation);
WRITE_UINT_FIELD(options);
+ WRITE_OID_FIELD(relationOid);
}
static void