diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-01-17 22:56:23 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-01-17 22:56:23 +0000 |
| commit | 9a915e596f38a97f10e00d388f18e178136937eb (patch) | |
| tree | c0f85775a2423e0fb28c4d96d85569781668011e /src/include/catalog/pg_trigger.h | |
| parent | ee3b4188a78916544ef30e93fc1c9e5e780e07d5 (diff) | |
| download | postgresql-9a915e596f38a97f10e00d388f18e178136937eb.tar.gz | |
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.
Diffstat (limited to 'src/include/catalog/pg_trigger.h')
| -rw-r--r-- | src/include/catalog/pg_trigger.h | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/src/include/catalog/pg_trigger.h b/src/include/catalog/pg_trigger.h index 8e1a4bf12b..7c95475043 100644 --- a/src/include/catalog/pg_trigger.h +++ b/src/include/catalog/pg_trigger.h @@ -8,7 +8,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/pg_trigger.h,v 1.38 2010/01/05 01:06:57 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/pg_trigger.h,v 1.39 2010/01/17 22:56:23 tgl Exp $ * * NOTES * the genbki.pl script reads this file and generates .bki @@ -25,11 +25,10 @@ * pg_trigger definition. cpp turns this into * typedef struct FormData_pg_trigger * - * Note: when tgconstraint is nonzero, tgisconstraint must be true, and - * tgconstrname, tgconstrrelid, tgconstrindid, tgdeferrable, tginitdeferred - * are redundant with the referenced pg_constraint entry. The reason we keep - * these fields is that we support "stand-alone" constraint triggers with no - * corresponding pg_constraint entry. + * Note: when tgconstraint is nonzero, tgconstrrelid, tgconstrindid, + * tgdeferrable, and tginitdeferred are largely redundant with the referenced + * pg_constraint entry. However, it is possible for a non-deferrable trigger + * to be associated with a deferrable constraint. * ---------------- */ #define TriggerRelationId 2620 @@ -43,11 +42,10 @@ CATALOG(pg_trigger,2620) * ROW/STATEMENT; see below */ char tgenabled; /* trigger's firing configuration WRT * session_replication_role */ - bool tgisconstraint; /* trigger is a constraint trigger */ - NameData tgconstrname; /* constraint name */ + bool tgisinternal; /* trigger is system-generated */ Oid tgconstrrelid; /* constraint's FROM table, if any */ Oid tgconstrindid; /* constraint's supporting index, if any */ - Oid tgconstraint; /* owning pg_constraint entry, if any */ + Oid tgconstraint; /* associated pg_constraint entry, if any */ bool tgdeferrable; /* constraint trigger is deferrable */ bool tginitdeferred; /* constraint trigger is deferred initially */ int2 tgnargs; /* # of extra arguments in tgargs */ @@ -69,23 +67,22 @@ typedef FormData_pg_trigger *Form_pg_trigger; * compiler constants for pg_trigger * ---------------- */ -#define Natts_pg_trigger 16 +#define Natts_pg_trigger 15 #define Anum_pg_trigger_tgrelid 1 #define Anum_pg_trigger_tgname 2 #define Anum_pg_trigger_tgfoid 3 #define Anum_pg_trigger_tgtype 4 #define Anum_pg_trigger_tgenabled 5 -#define Anum_pg_trigger_tgisconstraint 6 -#define Anum_pg_trigger_tgconstrname 7 -#define Anum_pg_trigger_tgconstrrelid 8 -#define Anum_pg_trigger_tgconstrindid 9 -#define Anum_pg_trigger_tgconstraint 10 -#define Anum_pg_trigger_tgdeferrable 11 -#define Anum_pg_trigger_tginitdeferred 12 -#define Anum_pg_trigger_tgnargs 13 -#define Anum_pg_trigger_tgattr 14 -#define Anum_pg_trigger_tgargs 15 -#define Anum_pg_trigger_tgqual 16 +#define Anum_pg_trigger_tgisinternal 6 +#define Anum_pg_trigger_tgconstrrelid 7 +#define Anum_pg_trigger_tgconstrindid 8 +#define Anum_pg_trigger_tgconstraint 9 +#define Anum_pg_trigger_tgdeferrable 10 +#define Anum_pg_trigger_tginitdeferred 11 +#define Anum_pg_trigger_tgnargs 12 +#define Anum_pg_trigger_tgattr 13 +#define Anum_pg_trigger_tgargs 14 +#define Anum_pg_trigger_tgqual 15 /* Bits within tgtype */ #define TRIGGER_TYPE_ROW (1 << 0) |
