diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-05-09 23:32:05 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-05-09 23:32:05 +0000 |
commit | cd902b331dc4b0c170e800441a98f9213d98b46b (patch) | |
tree | bef3eacf7ff474dd0fb96b368e80137f73658d52 /src/bin/pg_dump/common.c | |
parent | f8df836ae396be28a6c9e4f79a6adf3e5c0187b5 (diff) | |
download | postgresql-cd902b331dc4b0c170e800441a98f9213d98b46b.tar.gz postgresql-cd902b331dc4b0c170e800441a98f9213d98b46b.zip |
Change the rules for inherited CHECK constraints to be essentially the same
as those for inherited columns; that is, it's no longer allowed for a child
table to not have a check constraint matching one that exists on a parent.
This satisfies the principle of least surprise (rows selected from the parent
will always appear to meet its check constraints) and eliminates some
longstanding bogosity in pg_dump, which formerly had to guess about whether
check constraints were really inherited or not.
The implementation involves adding conislocal and coninhcount columns to
pg_constraint (paralleling attislocal and attinhcount in pg_attribute)
and refactoring various ALTER TABLE actions to be more like those for
columns.
Alex Hunsaker, Nikhil Sontakke, Tom Lane
Diffstat (limited to 'src/bin/pg_dump/common.c')
-rw-r--r-- | src/bin/pg_dump/common.c | 47 |
1 files changed, 4 insertions, 43 deletions
diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c index 2d41a52e191..8950dee0ca8 100644 --- a/src/bin/pg_dump/common.c +++ b/src/bin/pg_dump/common.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/common.c,v 1.103 2008/03/27 03:57:33 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/common.c,v 1.104 2008/05/09 23:32:04 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -62,8 +62,7 @@ static DumpableObject **oprinfoindex; static void flagInhTables(TableInfo *tbinfo, int numTables, InhInfo *inhinfo, int numInherits); -static void flagInhAttrs(TableInfo *tbinfo, int numTables, - InhInfo *inhinfo, int numInherits); +static void flagInhAttrs(TableInfo *tblinfo, int numTables); static DumpableObject **buildIndexArray(void *objArray, int numObjs, Size objSize); static int DOCatalogIdCompare(const void *p1, const void *p2); @@ -191,7 +190,7 @@ getSchemaData(int *numTablesPtr) if (g_verbose) write_msg(NULL, "flagging inherited columns in subtables\n"); - flagInhAttrs(tblinfo, numTables, inhinfo, numInherits); + flagInhAttrs(tblinfo, numTables); if (g_verbose) write_msg(NULL, "reading indexes\n"); @@ -257,8 +256,7 @@ flagInhTables(TableInfo *tblinfo, int numTables, * modifies tblinfo */ static void -flagInhAttrs(TableInfo *tblinfo, int numTables, - InhInfo *inhinfo, int numInherits) +flagInhAttrs(TableInfo *tblinfo, int numTables) { int i, j, @@ -414,43 +412,6 @@ flagInhAttrs(TableInfo *tblinfo, int numTables, tbinfo->inhAttrs[j] = false; } } - - /* - * Check for inherited CHECK constraints. We assume a constraint is - * inherited if its name matches the name of any constraint in the - * parent. Originally this code tried to compare the expression - * texts, but that can fail if the parent and child tables are in - * different schemas, because reverse-listing of function calls may - * produce different text (schema-qualified or not) depending on - * search path. We really need a more bulletproof way of detecting - * inherited constraints --- pg_constraint should record this - * explicitly! - */ - for (j = 0; j < tbinfo->ncheck; j++) - { - ConstraintInfo *constr; - - constr = &(tbinfo->checkexprs[j]); - - for (k = 0; k < numParents; k++) - { - int l; - - parent = parents[k]; - for (l = 0; l < parent->ncheck; l++) - { - ConstraintInfo *pconstr = &(parent->checkexprs[l]); - - if (strcmp(pconstr->dobj.name, constr->dobj.name) == 0) - { - constr->coninherited = true; - break; - } - } - if (constr->coninherited) - break; - } - } } } |