aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorÁlvaro Herrera <alvherre@alvh.no-ip.org>2025-01-26 17:34:28 +0100
committerÁlvaro Herrera <alvherre@alvh.no-ip.org>2025-01-26 17:34:28 +0100
commit0a16c8326c5a14abd180eeefe5e5ee4263513c2a (patch)
tree66d5f38a656f9a3410c6815e7471715a258ae293 /src/backend/commands/tablecmds.c
parentd28cd3e7b21c41a710fd9c188a57dad99f28805f (diff)
downloadpostgresql-0a16c8326c5a14abd180eeefe5e5ee4263513c2a.tar.gz
postgresql-0a16c8326c5a14abd180eeefe5e5ee4263513c2a.zip
Add missing CommandCounterIncrement
For commit b663b9436e75 I thought this was useless, but turns out not to be for the case where a partitioned table has two identical foreign key constraints which can both be matched by the same constraint in a partition during attach. This CCI makes the match search for the second constraint in the parent ignore the constraint in the child that has already been matched by the first constraint in the parent. Reported-by: Alexander Lakhin <exclusion@gmail.com> Discussion: https://postgr.es/m/c599253c-1ccd-4161-80fc-c9065e037a09@gmail.com
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 57662fd7662..96a48ba82c1 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -11564,22 +11564,22 @@ tryAttachPartitionForeignKey(List **wqueue,
table_close(pg_constraint, RowShareLock);
}
+ /*
+ * We updated this pg_constraint row above to set its parent; validating
+ * it will cause its convalidated flag to change, so we need CCI here. In
+ * addition, we need it unconditionally for the rare case where the parent
+ * table has *two* identical constraints; when reaching this function for
+ * the second one, we must have made our changes visible, otherwise we
+ * would try to attach both to this one.
+ */
+ CommandCounterIncrement();
+
/* If validation is needed, put it in the queue now. */
if (queueValidation)
{
Relation conrel;
- /*
- * We updated this pg_constraint row above to set its parent;
- * validating it will cause its convalidated flag to change, so we
- * need CCI here. XXX it might work better to effect the convalidated
- * changes for all constraints together during phase 3, but that
- * requires more invasive code surgery.
- */
- CommandCounterIncrement();
-
conrel = table_open(ConstraintRelationId, RowExclusiveLock);
-
partcontup = SearchSysCache1(CONSTROID, ObjectIdGetDatum(fk->conoid));
if (!HeapTupleIsValid(partcontup))
elog(ERROR, "cache lookup failed for constraint %u", fk->conoid);