mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Add a WHEN clause to CREATE TRIGGER, allowing a boolean expression to be
checked to determine whether the trigger should be fired. For BEFORE triggers this is mostly a matter of spec compliance; but for AFTER triggers it can provide a noticeable performance improvement, since queuing of a deferred trigger event and re-fetching of the row(s) at end of statement can be short-circuited if the trigger does not need to be fired. Takahiro Itagaki, reviewed by KaiGai Kohei.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.305 2009/11/04 12:24:23 heikki Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.306 2009/11/20 20:38:10 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -5403,7 +5403,7 @@ validateForeignKeyConstraint(Constraint *fkconstraint,
|
||||
trig.tgconstraint = constraintOid;
|
||||
trig.tgdeferrable = FALSE;
|
||||
trig.tginitdeferred = FALSE;
|
||||
/* we needn't fill in tgargs */
|
||||
/* we needn't fill in tgargs or tgqual */
|
||||
|
||||
/*
|
||||
* See if we can do it with a single LEFT JOIN query. A FALSE result
|
||||
@ -5476,13 +5476,14 @@ CreateFKCheckTrigger(RangeVar *myRel, Constraint *fkconstraint,
|
||||
}
|
||||
|
||||
fk_trigger->columns = NIL;
|
||||
fk_trigger->whenClause = NULL;
|
||||
fk_trigger->isconstraint = true;
|
||||
fk_trigger->deferrable = fkconstraint->deferrable;
|
||||
fk_trigger->initdeferred = fkconstraint->initdeferred;
|
||||
fk_trigger->constrrel = fkconstraint->pktable;
|
||||
fk_trigger->args = NIL;
|
||||
|
||||
(void) CreateTrigger(fk_trigger, constraintOid, indexOid,
|
||||
(void) CreateTrigger(fk_trigger, NULL, constraintOid, indexOid,
|
||||
"RI_ConstraintTrigger", false);
|
||||
|
||||
/* Make changes-so-far visible */
|
||||
@ -5527,6 +5528,7 @@ createForeignKeyTriggers(Relation rel, Constraint *fkconstraint,
|
||||
fk_trigger->row = true;
|
||||
fk_trigger->events = TRIGGER_TYPE_DELETE;
|
||||
fk_trigger->columns = NIL;
|
||||
fk_trigger->whenClause = NULL;
|
||||
fk_trigger->isconstraint = true;
|
||||
fk_trigger->constrrel = myRel;
|
||||
switch (fkconstraint->fk_del_action)
|
||||
@ -5563,7 +5565,7 @@ createForeignKeyTriggers(Relation rel, Constraint *fkconstraint,
|
||||
}
|
||||
fk_trigger->args = NIL;
|
||||
|
||||
(void) CreateTrigger(fk_trigger, constraintOid, indexOid,
|
||||
(void) CreateTrigger(fk_trigger, NULL, constraintOid, indexOid,
|
||||
"RI_ConstraintTrigger", false);
|
||||
|
||||
/* Make changes-so-far visible */
|
||||
@ -5580,6 +5582,7 @@ createForeignKeyTriggers(Relation rel, Constraint *fkconstraint,
|
||||
fk_trigger->row = true;
|
||||
fk_trigger->events = TRIGGER_TYPE_UPDATE;
|
||||
fk_trigger->columns = NIL;
|
||||
fk_trigger->whenClause = NULL;
|
||||
fk_trigger->isconstraint = true;
|
||||
fk_trigger->constrrel = myRel;
|
||||
switch (fkconstraint->fk_upd_action)
|
||||
@ -5616,7 +5619,7 @@ createForeignKeyTriggers(Relation rel, Constraint *fkconstraint,
|
||||
}
|
||||
fk_trigger->args = NIL;
|
||||
|
||||
(void) CreateTrigger(fk_trigger, constraintOid, indexOid,
|
||||
(void) CreateTrigger(fk_trigger, NULL, constraintOid, indexOid,
|
||||
"RI_ConstraintTrigger", false);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user