From e4a5dc7b8e78b206253982ca06311af1b33f79ae Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 3 Aug 2010 15:47:09 +0000 Subject: [PATCH] Fix inheritance count tracking in ALTER TABLE .. ADD CONSTRAINT. Without this patch, constraints inherited by children of a parent table which itself has multiple inheritance parents can end up with the wrong coninhcount. After dropping the constraint, the children end up with a leftover copy of the constraint that is not dumped and cannot be dropped. There is a similar problem with ALTER TABLE .. ADD COLUMN, but that looks significantly more difficult to resolve, so I'm committing this fix separately. Back-patch to 8.4, which is the first release that has coninhcount. Report by Hank Enting. --- src/backend/commands/tablecmds.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index ff27b7371f4..4c79f8f7e4d 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.332.2.2 2010/07/29 19:23:28 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.332.2.3 2010/08/03 15:47:09 rhaas Exp $ * *------------------------------------------------------------------------- */ @@ -4702,6 +4702,15 @@ ATAddCheckConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, /* Advance command counter in case same table is visited multiple times */ CommandCounterIncrement(); + /* + * If the constraint got merged with an existing constraint, we're done. + * We mustn't recurse to child tables in this case, because they've already + * got the constraint, and visiting them again would lead to an incorrect + * value for coninhcount. + */ + if (newcons == NIL) + return; + /* * Propagate to children as appropriate. Unlike most other ALTER * routines, we have to do this one level of recursion at a time; we can't -- 2.39.5