summaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index f3d64c6a9ec..d07476d8ddf 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -8549,13 +8549,13 @@ CloneFkReferenced(Relation parentRel, Relation partitionRel)
List *clone = NIL;
/*
- * Search for any constraints where this partition is in the referenced
- * side. However, we must ignore any constraint whose parent constraint
- * is also going to be cloned, to avoid duplicates. So do it in two
- * steps: first construct the list of constraints to clone, then go over
- * that list cloning those whose parents are not in the list. (We must
- * not rely on the parent being seen first, since the catalog scan could
- * return children first.)
+ * Search for any constraints where this partition's parent is in the
+ * referenced side. However, we must not clone any constraint whose
+ * parent constraint is also going to be cloned, to avoid duplicates. So
+ * do it in two steps: first construct the list of constraints to clone,
+ * then go over that list cloning those whose parents are not in the list.
+ * (We must not rely on the parent being seen first, since the catalog
+ * scan could return children first.)
*/
pg_constraint = table_open(ConstraintRelationId, RowShareLock);
ScanKeyInit(&key[0],
@@ -8571,10 +8571,6 @@ CloneFkReferenced(Relation parentRel, Relation partitionRel)
{
Form_pg_constraint constrForm = (Form_pg_constraint) GETSTRUCT(tuple);
- /* Only try to clone the top-level constraint; skip child ones. */
- if (constrForm->conparentid != InvalidOid)
- continue;
-
clone = lappend_oid(clone, constrForm->oid);
}
systable_endscan(scan);
@@ -8605,6 +8601,16 @@ CloneFkReferenced(Relation parentRel, Relation partitionRel)
constrForm = (Form_pg_constraint) GETSTRUCT(tuple);
/*
+ * As explained above: don't try to clone a constraint for which we're
+ * going to clone the parent.
+ */
+ if (list_member_oid(clone, constrForm->conparentid))
+ {
+ ReleaseSysCache(tuple);
+ continue;
+ }
+
+ /*
* Because we're only expanding the key space at the referenced side,
* we don't need to prevent any operation in the referencing table, so
* AccessShareLock suffices (assumes that dropping the constraint