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

Commit c905b67

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 076cfff commit c905b67

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/backend/catalog/pg_constraint.c

Lines changed: 1 addition & 0 deletions
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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14219,21 +14219,21 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1421914219
RelationGetRelid(attachrel), &cloned);
1422014220
foreach(l, cloned)
1422114221
{
14222-
ClonedConstraint *cloned = lfirst(l);
14222+
ClonedConstraint *clonedcon = lfirst(l);
1422314223
NewConstraint *newcon;
1422414224
Relation clonedrel;
1422514225
AlteredTableInfo *parttab;
1422614226

14227-
clonedrel = relation_open(cloned->relid, NoLock);
14227+
clonedrel = relation_open(clonedcon->relid, NoLock);
1422814228
parttab = ATGetQueueEntry(wqueue, clonedrel);
1422914229

1423014230
newcon = (NewConstraint *) palloc0(sizeof(NewConstraint));
14231-
newcon->name = cloned->constraint->conname;
14231+
newcon->name = clonedcon->constraint->conname;
1423214232
newcon->contype = CONSTR_FOREIGN;
14233-
newcon->refrelid = cloned->refrelid;
14234-
newcon->refindid = cloned->conindid;
14235-
newcon->conid = cloned->conid;
14236-
newcon->qual = (Node *) cloned->constraint;
14233+
newcon->refrelid = clonedcon->refrelid;
14234+
newcon->refindid = clonedcon->conindid;
14235+
newcon->conid = clonedcon->conid;
14236+
newcon->qual = (Node *) clonedcon->constraint;
1423714237

1423814238
parttab->constraints = lappend(parttab->constraints, newcon);
1423914239

0 commit comments

Comments
 (0)