aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-01-17 22:56:23 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-01-17 22:56:23 +0000
commit9a915e596f38a97f10e00d388f18e178136937eb (patch)
treec0f85775a2423e0fb28c4d96d85569781668011e /src/backend/commands/tablecmds.c
parentee3b4188a78916544ef30e93fc1c9e5e780e07d5 (diff)
downloadpostgresql-9a915e596f38a97f10e00d388f18e178136937eb.tar.gz
postgresql-9a915e596f38a97f10e00d388f18e178136937eb.zip
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/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index bf1234614c9..43d8c0c56bf 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.315 2010/01/15 09:19:01 heikki Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.316 2010/01/17 22:56:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -5338,7 +5338,7 @@ validateForeignKeyConstraint(Constraint *fkconstraint,
trig.tgoid = InvalidOid;
trig.tgname = fkconstraint->conname;
trig.tgenabled = TRIGGER_FIRES_ON_ORIGIN;
- trig.tgisconstraint = TRUE;
+ trig.tgisinternal = TRUE;
trig.tgconstrrelid = RelationGetRelid(pkrel);
trig.tgconstrindid = pkindOid;
trig.tgconstraint = constraintOid;
@@ -5399,7 +5399,7 @@ CreateFKCheckTrigger(RangeVar *myRel, Constraint *fkconstraint,
CreateTrigStmt *fk_trigger;
fk_trigger = makeNode(CreateTrigStmt);
- fk_trigger->trigname = fkconstraint->conname;
+ fk_trigger->trigname = "RI_ConstraintTrigger";
fk_trigger->relation = myRel;
fk_trigger->before = false;
fk_trigger->row = true;
@@ -5424,8 +5424,7 @@ CreateFKCheckTrigger(RangeVar *myRel, Constraint *fkconstraint,
fk_trigger->constrrel = fkconstraint->pktable;
fk_trigger->args = NIL;
- (void) CreateTrigger(fk_trigger, NULL, constraintOid, indexOid,
- "RI_ConstraintTrigger", false);
+ (void) CreateTrigger(fk_trigger, NULL, constraintOid, indexOid, true);
/* Make changes-so-far visible */
CommandCounterIncrement();
@@ -5463,7 +5462,7 @@ createForeignKeyTriggers(Relation rel, Constraint *fkconstraint,
* DELETE action on the referenced table.
*/
fk_trigger = makeNode(CreateTrigStmt);
- fk_trigger->trigname = fkconstraint->conname;
+ fk_trigger->trigname = "RI_ConstraintTrigger";
fk_trigger->relation = fkconstraint->pktable;
fk_trigger->before = false;
fk_trigger->row = true;
@@ -5506,8 +5505,7 @@ createForeignKeyTriggers(Relation rel, Constraint *fkconstraint,
}
fk_trigger->args = NIL;
- (void) CreateTrigger(fk_trigger, NULL, constraintOid, indexOid,
- "RI_ConstraintTrigger", false);
+ (void) CreateTrigger(fk_trigger, NULL, constraintOid, indexOid, true);
/* Make changes-so-far visible */
CommandCounterIncrement();
@@ -5517,7 +5515,7 @@ createForeignKeyTriggers(Relation rel, Constraint *fkconstraint,
* UPDATE action on the referenced table.
*/
fk_trigger = makeNode(CreateTrigStmt);
- fk_trigger->trigname = fkconstraint->conname;
+ fk_trigger->trigname = "RI_ConstraintTrigger";
fk_trigger->relation = fkconstraint->pktable;
fk_trigger->before = false;
fk_trigger->row = true;
@@ -5560,8 +5558,7 @@ createForeignKeyTriggers(Relation rel, Constraint *fkconstraint,
}
fk_trigger->args = NIL;
- (void) CreateTrigger(fk_trigger, NULL, constraintOid, indexOid,
- "RI_ConstraintTrigger", false);
+ (void) CreateTrigger(fk_trigger, NULL, constraintOid, indexOid, true);
}
/*