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/executor/execQual.c,v 1.254 2009/11/04 22:26:05 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.255 2009/11/20 20:38:10 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -491,26 +491,15 @@ ExecEvalVar(ExprState *exprstate, ExprContext *econtext,
|
||||
if (isDone)
|
||||
*isDone = ExprSingleResult;
|
||||
|
||||
/*
|
||||
* Get the input slot and attribute number we want
|
||||
*
|
||||
* The asserts check that references to system attributes only appear at
|
||||
* the level of a relation scan; at higher levels, system attributes must
|
||||
* be treated as ordinary variables (since we no longer have access to the
|
||||
* original tuple).
|
||||
*/
|
||||
attnum = variable->varattno;
|
||||
|
||||
/* Get the input slot and attribute number we want */
|
||||
switch (variable->varno)
|
||||
{
|
||||
case INNER: /* get the tuple from the inner node */
|
||||
slot = econtext->ecxt_innertuple;
|
||||
Assert(attnum > 0);
|
||||
break;
|
||||
|
||||
case OUTER: /* get the tuple from the outer node */
|
||||
slot = econtext->ecxt_outertuple;
|
||||
Assert(attnum > 0);
|
||||
break;
|
||||
|
||||
default: /* get the tuple from the relation being
|
||||
@ -519,6 +508,8 @@ ExecEvalVar(ExprState *exprstate, ExprContext *econtext,
|
||||
break;
|
||||
}
|
||||
|
||||
attnum = variable->varattno;
|
||||
|
||||
if (attnum != InvalidAttrNumber)
|
||||
{
|
||||
/*
|
||||
@ -715,7 +706,7 @@ ExecEvalWholeRowVar(ExprState *exprstate, ExprContext *econtext,
|
||||
bool *isNull, ExprDoneCond *isDone)
|
||||
{
|
||||
Var *variable = (Var *) exprstate->expr;
|
||||
TupleTableSlot *slot = econtext->ecxt_scantuple;
|
||||
TupleTableSlot *slot;
|
||||
HeapTuple tuple;
|
||||
TupleDesc tupleDesc;
|
||||
HeapTupleHeader dtuple;
|
||||
@ -724,6 +715,23 @@ ExecEvalWholeRowVar(ExprState *exprstate, ExprContext *econtext,
|
||||
*isDone = ExprSingleResult;
|
||||
*isNull = false;
|
||||
|
||||
/* Get the input slot we want */
|
||||
switch (variable->varno)
|
||||
{
|
||||
case INNER: /* get the tuple from the inner node */
|
||||
slot = econtext->ecxt_innertuple;
|
||||
break;
|
||||
|
||||
case OUTER: /* get the tuple from the outer node */
|
||||
slot = econtext->ecxt_outertuple;
|
||||
break;
|
||||
|
||||
default: /* get the tuple from the relation being
|
||||
* scanned */
|
||||
slot = econtext->ecxt_scantuple;
|
||||
break;
|
||||
}
|
||||
|
||||
tuple = ExecFetchSlotTuple(slot);
|
||||
tupleDesc = slot->tts_tupleDescriptor;
|
||||
|
||||
@ -766,7 +774,7 @@ ExecEvalWholeRowSlow(ExprState *exprstate, ExprContext *econtext,
|
||||
bool *isNull, ExprDoneCond *isDone)
|
||||
{
|
||||
Var *variable = (Var *) exprstate->expr;
|
||||
TupleTableSlot *slot = econtext->ecxt_scantuple;
|
||||
TupleTableSlot *slot;
|
||||
HeapTuple tuple;
|
||||
TupleDesc var_tupdesc;
|
||||
HeapTupleHeader dtuple;
|
||||
@ -775,6 +783,23 @@ ExecEvalWholeRowSlow(ExprState *exprstate, ExprContext *econtext,
|
||||
*isDone = ExprSingleResult;
|
||||
*isNull = false;
|
||||
|
||||
/* Get the input slot we want */
|
||||
switch (variable->varno)
|
||||
{
|
||||
case INNER: /* get the tuple from the inner node */
|
||||
slot = econtext->ecxt_innertuple;
|
||||
break;
|
||||
|
||||
case OUTER: /* get the tuple from the outer node */
|
||||
slot = econtext->ecxt_outertuple;
|
||||
break;
|
||||
|
||||
default: /* get the tuple from the relation being
|
||||
* scanned */
|
||||
slot = econtext->ecxt_scantuple;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Currently, the only case handled here is stripping of trailing resjunk
|
||||
* fields, which we do in a slightly chintzy way by just adjusting the
|
||||
|
Reference in New Issue
Block a user