mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Fix trigger WHEN conditions when both BEFORE and AFTER triggers exist.
Due to tuple-slot mismanagement, evaluation of WHEN conditions for AFTER ROW UPDATE triggers could crash if there had been a BEFORE ROW trigger fired for the same update. Fix by not trying to overload the use of estate->es_trig_tuple_slot. Per report from Yoran Heling. Back-patch to 9.0, when trigger WHEN conditions were introduced.
This commit is contained in:
@@ -2755,13 +2755,13 @@ TriggerEnabled(EState *estate, ResultRelInfo *relinfo,
|
||||
}
|
||||
if (HeapTupleIsValid(newtup))
|
||||
{
|
||||
if (estate->es_trig_tuple_slot == NULL)
|
||||
if (estate->es_trig_newtup_slot == NULL)
|
||||
{
|
||||
oldContext = MemoryContextSwitchTo(estate->es_query_cxt);
|
||||
estate->es_trig_tuple_slot = ExecInitExtraTupleSlot(estate);
|
||||
estate->es_trig_newtup_slot = ExecInitExtraTupleSlot(estate);
|
||||
MemoryContextSwitchTo(oldContext);
|
||||
}
|
||||
newslot = estate->es_trig_tuple_slot;
|
||||
newslot = estate->es_trig_newtup_slot;
|
||||
if (newslot->tts_tupleDescriptor != tupdesc)
|
||||
ExecSetSlotDescriptor(newslot, tupdesc);
|
||||
ExecStoreTuple(newtup, newslot, InvalidBuffer, false);
|
||||
|
@@ -871,6 +871,7 @@ InitPlan(QueryDesc *queryDesc, int eflags)
|
||||
estate->es_tupleTable = NIL;
|
||||
estate->es_trig_tuple_slot = NULL;
|
||||
estate->es_trig_oldtup_slot = NULL;
|
||||
estate->es_trig_newtup_slot = NULL;
|
||||
|
||||
/* mark EvalPlanQual not active */
|
||||
estate->es_epqTuple = NULL;
|
||||
|
@@ -124,6 +124,7 @@ CreateExecutorState(void)
|
||||
estate->es_trig_target_relations = NIL;
|
||||
estate->es_trig_tuple_slot = NULL;
|
||||
estate->es_trig_oldtup_slot = NULL;
|
||||
estate->es_trig_newtup_slot = NULL;
|
||||
|
||||
estate->es_param_list_info = NULL;
|
||||
estate->es_param_exec_vals = NULL;
|
||||
|
Reference in New Issue
Block a user