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 /contrib/postgres_fdw/postgres_fdw.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 'contrib/postgres_fdw/postgres_fdw.c')
-rw-r--r-- | contrib/postgres_fdw/postgres_fdw.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index 6b96e7de0a4..2f387fac422 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -3507,8 +3507,13 @@ store_returning_result(PgFdwModifyState *fmstate, fmstate->retrieved_attrs, NULL, fmstate->temp_cxt); - /* tuple will be deleted when it is cleared from the slot */ - ExecStoreHeapTuple(newtup, slot, true); + /* + * The returning slot will not necessarily be suitable to store + * heaptuples directly, so allow for conversion. + */ + ExecForceStoreHeapTuple(newtup, slot); + ExecMaterializeSlot(slot); + pfree(newtup); } PG_CATCH(); { @@ -3886,6 +3891,7 @@ apply_returning_filter(PgFdwDirectModifyState *dmstate, TupleTableSlot *slot, EState *estate) { + ResultRelInfo *relInfo = estate->es_result_relation_info; TupleDesc resultTupType = RelationGetDescr(dmstate->resultRel); TupleTableSlot *resultSlot; Datum *values; @@ -3895,11 +3901,9 @@ apply_returning_filter(PgFdwDirectModifyState *dmstate, int i; /* - * Use the trigger tuple slot as a place to store the result tuple. + * Use the return tuple slot as a place to store the result tuple. */ - resultSlot = estate->es_trig_tuple_slot; - if (resultSlot->tts_tupleDescriptor != resultTupType) - ExecSetSlotDescriptor(resultSlot, resultTupType); + resultSlot = ExecGetReturningSlot(estate, relInfo); /* * Extract all the values of the scan tuple. |