aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2010-08-03 15:47:16 +0000
committerRobert Haas <rhaas@postgresql.org>2010-08-03 15:47:16 +0000
commita6542f90f9f720862d4c2b34e6d77efd94a8d47c (patch)
tree645916a67a16ca643d0ef6c980d864bec18b40d8 /src/backend/commands/tablecmds.c
parent9f4b99afbb3861ab2344b1db62193b4673126ce5 (diff)
downloadpostgresql-a6542f90f9f720862d4c2b34e6d77efd94a8d47c.tar.gz
postgresql-a6542f90f9f720862d4c2b34e6d77efd94a8d47c.zip
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.
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index d07e51fb658..da491e14ef2 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.288.2.5 2010/07/29 19:23:37 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.288.2.6 2010/08/03 15:47:16 rhaas Exp $
*
*-------------------------------------------------------------------------
*/
@@ -4525,6 +4525,15 @@ ATAddCheckConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
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
* use find_all_inheritors to do it in one pass.