aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2018-10-06 14:59:52 +0900
committerMichael Paquier <michael@paquier.xyz>2018-10-06 14:59:52 +0900
commitc905b67b79b72b88ba80d2486443c824232c6d85 (patch)
tree6cdfe1493bc1e12d9453e6fa4804b20403760a34 /src
parent076cfffb39af281f4e3b7d9852715bb09e214171 (diff)
downloadpostgresql-c905b67b79b72b88ba80d2486443c824232c6d85.tar.gz
postgresql-c905b67b79b72b88ba80d2486443c824232c6d85.zip
Assign constraint name when cloning FK definition for partitions
This is for example used when attaching a partition to a partitioned table which includes foreign keys, and in this case the constraint name has been missing in the data cloned. This could lead to hard crashes, as when validating the foreign key constraint, the constraint name is always expected. Particularly, when using log_min_messages >= DEBUG1, a log message would be generated with this unassigned constraint name, leading to an assertion failure on HEAD. While on it, rename a variable in ATExecAttachPartition which was declared twice with the same name. Author: Michael Paquier Reviewed-by: Álvaro Herrera Discussion: https://postgr.es/m/20181005042236.GG1629@paquier.xyz Backpatch-through: 11
Diffstat (limited to 'src')
-rw-r--r--src/backend/catalog/pg_constraint.c1
-rw-r--r--src/backend/commands/tablecmds.c14
2 files changed, 8 insertions, 7 deletions
diff --git a/src/backend/catalog/pg_constraint.c b/src/backend/catalog/pg_constraint.c
index 6781b00c6e6..2063abb8aeb 100644
--- a/src/backend/catalog/pg_constraint.c
+++ b/src/backend/catalog/pg_constraint.c
@@ -574,6 +574,7 @@ CloneForeignKeyConstraints(Oid parentId, Oid relationId, List **cloned)
fkconstraint = makeNode(Constraint);
/* for now this is all we need */
+ fkconstraint->conname = pstrdup(NameStr(constrForm->conname));
fkconstraint->fk_upd_action = constrForm->confupdtype;
fkconstraint->fk_del_action = constrForm->confdeltype;
fkconstraint->deferrable = constrForm->condeferrable;
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index b0cbf2e1378..61fefe1d7ca 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -14219,21 +14219,21 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
RelationGetRelid(attachrel), &cloned);
foreach(l, cloned)
{
- ClonedConstraint *cloned = lfirst(l);
+ ClonedConstraint *clonedcon = lfirst(l);
NewConstraint *newcon;
Relation clonedrel;
AlteredTableInfo *parttab;
- clonedrel = relation_open(cloned->relid, NoLock);
+ clonedrel = relation_open(clonedcon->relid, NoLock);
parttab = ATGetQueueEntry(wqueue, clonedrel);
newcon = (NewConstraint *) palloc0(sizeof(NewConstraint));
- newcon->name = cloned->constraint->conname;
+ newcon->name = clonedcon->constraint->conname;
newcon->contype = CONSTR_FOREIGN;
- newcon->refrelid = cloned->refrelid;
- newcon->refindid = cloned->conindid;
- newcon->conid = cloned->conid;
- newcon->qual = (Node *) cloned->constraint;
+ newcon->refrelid = clonedcon->refrelid;
+ newcon->refindid = clonedcon->conindid;
+ newcon->conid = clonedcon->conid;
+ newcon->qual = (Node *) clonedcon->constraint;
parttab->constraints = lappend(parttab->constraints, newcon);