Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 38921d1

Browse files
committed
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
1 parent 6eb612f commit 38921d1

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/backend/catalog/pg_constraint.c

+1
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ CloneForeignKeyConstraints(Oid parentId, Oid relationId, List **cloned)
574574

575575
fkconstraint = makeNode(Constraint);
576576
/* for now this is all we need */
577+
fkconstraint->conname = pstrdup(NameStr(constrForm->conname));
577578
fkconstraint->fk_upd_action = constrForm->confupdtype;
578579
fkconstraint->fk_del_action = constrForm->confdeltype;
579580
fkconstraint->deferrable = constrForm->condeferrable;

src/backend/commands/tablecmds.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -14275,21 +14275,21 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1427514275
RelationGetRelid(attachrel), &cloned);
1427614276
foreach(l, cloned)
1427714277
{
14278-
ClonedConstraint *cloned = lfirst(l);
14278+
ClonedConstraint *clonedcon = lfirst(l);
1427914279
NewConstraint *newcon;
1428014280
Relation clonedrel;
1428114281
AlteredTableInfo *parttab;
1428214282

14283-
clonedrel = relation_open(cloned->relid, NoLock);
14283+
clonedrel = relation_open(clonedcon->relid, NoLock);
1428414284
parttab = ATGetQueueEntry(wqueue, clonedrel);
1428514285

1428614286
newcon = (NewConstraint *) palloc0(sizeof(NewConstraint));
14287-
newcon->name = cloned->constraint->conname;
14287+
newcon->name = clonedcon->constraint->conname;
1428814288
newcon->contype = CONSTR_FOREIGN;
14289-
newcon->refrelid = cloned->refrelid;
14290-
newcon->refindid = cloned->conindid;
14291-
newcon->conid = cloned->conid;
14292-
newcon->qual = (Node *) cloned->constraint;
14289+
newcon->refrelid = clonedcon->refrelid;
14290+
newcon->refindid = clonedcon->conindid;
14291+
newcon->conid = clonedcon->conid;
14292+
newcon->qual = (Node *) clonedcon->constraint;
1429314293

1429414294
parttab->constraints = lappend(parttab->constraints, newcon);
1429514295

0 commit comments

Comments
 (0)