1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

Improve the handling of SET CONSTRAINTS commands by having them search

pg_constraint before searching pg_trigger.  This allows saner handling of
corner cases; in particular we now say "constraint is not deferrable"
rather than "constraint does not exist" when the command is applied to
a constraint that's inherently non-deferrable.  Per a gripe several months
ago from hubert depesz lubaczewski.

To make this work without breaking user-defined constraint triggers,
we have to add entries for them to pg_constraint.  However, in return
we can remove the pgconstrname column from pg_constraint, which represents
a fairly sizable space savings.  I also replaced the tgisconstraint column
with tgisinternal; the old meaning of tgisconstraint can now be had by
testing for nonzero tgconstraint, while there is no other way to get
the old meaning of nonzero tgconstraint, namely that the trigger was
internally generated rather than being user-created.

In passing, fix an old misstatement in the docs and comments, namely that
pg_trigger.tgdeferrable is exactly redundant with pg_constraint.condeferrable.
Actually, we mark RI action triggers as nondeferrable even when they belong to
a nominally deferrable FK constraint.  The SET CONSTRAINTS code now relies on
that instead of hard-coding a list of exception OIDs.
This commit is contained in:
Tom Lane
2010-01-17 22:56:23 +00:00
parent ee3b4188a7
commit 9a915e596f
17 changed files with 293 additions and 235 deletions

View File

@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.318 2010/01/02 16:57:55 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.319 2010/01/17 22:56:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -519,7 +519,7 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty)
tgname = NameStr(trigrec->tgname);
appendStringInfo(&buf, "CREATE %sTRIGGER %s",
trigrec->tgisconstraint ? "CONSTRAINT " : "",
OidIsValid(trigrec->tgconstraint) ? "CONSTRAINT " : "",
quote_identifier(tgname));
appendStringInfoString(&buf, pretty ? "\n " : " ");
@ -577,7 +577,7 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty)
generate_relation_name(trigrec->tgrelid, NIL));
appendStringInfoString(&buf, pretty ? "\n " : " ");
if (trigrec->tgisconstraint)
if (OidIsValid(trigrec->tgconstraint))
{
if (OidIsValid(trigrec->tgconstrrelid))
{
@ -1276,6 +1276,15 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
break;
}
case CONSTRAINT_TRIGGER:
/*
* There isn't an ALTER TABLE syntax for creating a user-defined
* constraint trigger, but it seems better to print something
* than throw an error; if we throw error then this function
* couldn't safely be applied to all rows of pg_constraint.
*/
appendStringInfo(&buf, "TRIGGER");
break;
case CONSTRAINT_EXCLUSION:
{
Oid indexOid = conForm->conindid;