mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
Use slots in trigger infrastructure, except for the actual invocation.
In preparation for abstracting table storage, convert trigger.c to track tuples in slots. Which also happens to make code calling triggers simpler. As the calling interface for triggers themselves is not changed in this patch, HeapTuples still are extracted from the slot at that time. But that's handled solely inside trigger.c, not visible to callers. It's quite likely that we'll want to revise the external trigger interface, but that's a separate large project. As part of this work the slots used for old/new/return tuples are moved from EState into ResultRelInfo, as different updated tables might need different slots. The slots are now also now created on-demand, which is good both from an efficiency POV, but also makes the modifying code simpler. Author: Andres Freund, Amit Khandekar and Ashutosh Bapat Discussion: https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de
This commit is contained in:
@ -2519,9 +2519,6 @@ CopyFrom(CopyState cstate)
|
||||
/* Set up a tuple slot too */
|
||||
myslot = ExecInitExtraTupleSlot(estate, tupDesc,
|
||||
&TTSOpsHeapTuple);
|
||||
/* Triggers might need a slot as well */
|
||||
estate->es_trig_tuple_slot = ExecInitExtraTupleSlot(estate, NULL,
|
||||
&TTSOpsHeapTuple);
|
||||
|
||||
/*
|
||||
* Set up a ModifyTableState so we can let FDW(s) init themselves for
|
||||
@ -2870,7 +2867,7 @@ CopyFrom(CopyState cstate)
|
||||
* Otherwise, just remember the original unconverted
|
||||
* tuple, to avoid a needless round trip conversion.
|
||||
*/
|
||||
cstate->transition_capture->tcs_original_insert_tuple = tuple;
|
||||
cstate->transition_capture->tcs_original_insert_tuple = myslot;
|
||||
cstate->transition_capture->tcs_map = NULL;
|
||||
}
|
||||
}
|
||||
@ -2907,12 +2904,8 @@ CopyFrom(CopyState cstate)
|
||||
/* BEFORE ROW INSERT Triggers */
|
||||
if (has_before_insert_row_trig)
|
||||
{
|
||||
slot = ExecBRInsertTriggers(estate, resultRelInfo, slot);
|
||||
|
||||
if (slot == NULL) /* "do nothing" */
|
||||
skip_tuple = true;
|
||||
else /* trigger might have changed tuple */
|
||||
tuple = ExecFetchSlotHeapTuple(slot, true, NULL);
|
||||
if (!ExecBRInsertTriggers(estate, resultRelInfo, slot))
|
||||
skip_tuple = true; /* "do nothing" */
|
||||
}
|
||||
|
||||
if (!skip_tuple)
|
||||
@ -2990,9 +2983,6 @@ CopyFrom(CopyState cstate)
|
||||
if (slot == NULL) /* "do nothing" */
|
||||
continue; /* next tuple please */
|
||||
|
||||
/* FDW might have changed tuple */
|
||||
tuple = ExecFetchSlotHeapTuple(slot, true, NULL);
|
||||
|
||||
/*
|
||||
* AFTER ROW Triggers might reference the tableoid
|
||||
* column, so (re-)initialize tts_tableOid before
|
||||
@ -3002,6 +2992,7 @@ CopyFrom(CopyState cstate)
|
||||
}
|
||||
else
|
||||
{
|
||||
tuple = ExecFetchSlotHeapTuple(slot, true, NULL);
|
||||
heap_insert(resultRelInfo->ri_RelationDesc, tuple,
|
||||
mycid, hi_options, bistate);
|
||||
ItemPointerCopy(&tuple->t_self, &slot->tts_tid);
|
||||
@ -3018,7 +3009,7 @@ CopyFrom(CopyState cstate)
|
||||
NIL);
|
||||
|
||||
/* AFTER ROW INSERT Triggers */
|
||||
ExecARInsertTriggers(estate, resultRelInfo, tuple,
|
||||
ExecARInsertTriggers(estate, resultRelInfo, slot,
|
||||
recheckIndexes, cstate->transition_capture);
|
||||
|
||||
list_free(recheckIndexes);
|
||||
@ -3158,7 +3149,7 @@ CopyFromInsertBatch(CopyState cstate, EState *estate, CommandId mycid,
|
||||
ExecInsertIndexTuples(myslot, &(bufferedTuples[i]->t_self),
|
||||
estate, false, NULL, NIL);
|
||||
ExecARInsertTriggers(estate, resultRelInfo,
|
||||
bufferedTuples[i],
|
||||
myslot,
|
||||
recheckIndexes, cstate->transition_capture);
|
||||
list_free(recheckIndexes);
|
||||
}
|
||||
@ -3175,8 +3166,9 @@ CopyFromInsertBatch(CopyState cstate, EState *estate, CommandId mycid,
|
||||
for (i = 0; i < nBufferedTuples; i++)
|
||||
{
|
||||
cstate->cur_lineno = firstBufferedLineNo + i;
|
||||
ExecStoreHeapTuple(bufferedTuples[i], myslot, false);
|
||||
ExecARInsertTriggers(estate, resultRelInfo,
|
||||
bufferedTuples[i],
|
||||
myslot,
|
||||
NIL, cstate->transition_capture);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user