diff options
author | Andres Freund <andres@anarazel.de> | 2019-02-26 20:30:28 -0800 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2019-02-26 20:31:38 -0800 |
commit | ff11e7f4b9ae017585c3ba146db7ba39c31f209a (patch) | |
tree | 37828b8d2ab7bda386b276129b456793c7ac908b /src/backend/commands/copy.c | |
parent | b8d71745eac0a12740a70dc78cbcdedadade37f8 (diff) | |
download | postgresql-ff11e7f4b9ae017585c3ba146db7ba39c31f209a.tar.gz postgresql-ff11e7f4b9ae017585c3ba146db7ba39c31f209a.zip |
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
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r-- | src/backend/commands/copy.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 93aa1631775..5dd6fe02c6e 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -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); } } |