aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/execUtils.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2019-02-26 20:30:28 -0800
committerAndres Freund <andres@anarazel.de>2019-02-26 20:31:38 -0800
commitff11e7f4b9ae017585c3ba146db7ba39c31f209a (patch)
tree37828b8d2ab7bda386b276129b456793c7ac908b /src/backend/executor/execUtils.c
parentb8d71745eac0a12740a70dc78cbcdedadade37f8 (diff)
downloadpostgresql-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/executor/execUtils.c')
-rw-r--r--src/backend/executor/execUtils.c69
1 files changed, 66 insertions, 3 deletions
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c
index 312a0dc8056..51362693481 100644
--- a/src/backend/executor/execUtils.c
+++ b/src/backend/executor/execUtils.c
@@ -131,9 +131,6 @@ CreateExecutorState(void)
estate->es_tuple_routing_result_relations = NIL;
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;
@@ -1102,3 +1099,69 @@ ExecCleanTargetListLength(List *targetlist)
}
return len;
}
+
+/*
+ * Return a relInfo's tuple slot for a trigger's OLD tuples.
+ */
+TupleTableSlot *
+ExecGetTriggerOldSlot(EState *estate, ResultRelInfo *relInfo)
+{
+ if (relInfo->ri_TrigOldSlot == NULL)
+ {
+ Relation rel = relInfo->ri_RelationDesc;
+ MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
+
+ relInfo->ri_TrigOldSlot =
+ ExecInitExtraTupleSlot(estate,
+ RelationGetDescr(rel),
+ &TTSOpsBufferHeapTuple);
+
+ MemoryContextSwitchTo(oldcontext);
+ }
+
+ return relInfo->ri_TrigOldSlot;
+}
+
+/*
+ * Return a relInfo's tuple slot for a trigger's NEW tuples.
+ */
+TupleTableSlot *
+ExecGetTriggerNewSlot(EState *estate, ResultRelInfo *relInfo)
+{
+ if (relInfo->ri_TrigNewSlot == NULL)
+ {
+ Relation rel = relInfo->ri_RelationDesc;
+ MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
+
+ relInfo->ri_TrigNewSlot =
+ ExecInitExtraTupleSlot(estate,
+ RelationGetDescr(rel),
+ &TTSOpsBufferHeapTuple);
+
+ MemoryContextSwitchTo(oldcontext);
+ }
+
+ return relInfo->ri_TrigNewSlot;
+}
+
+/*
+ * Return a relInfo's tuple slot for processing returning tuples.
+ */
+TupleTableSlot *
+ExecGetReturningSlot(EState *estate, ResultRelInfo *relInfo)
+{
+ if (relInfo->ri_ReturningSlot == NULL)
+ {
+ Relation rel = relInfo->ri_RelationDesc;
+ MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
+
+ relInfo->ri_ReturningSlot =
+ ExecInitExtraTupleSlot(estate,
+ RelationGetDescr(rel),
+ &TTSOpsBufferHeapTuple);
+
+ MemoryContextSwitchTo(oldcontext);
+ }
+
+ return relInfo->ri_ReturningSlot;
+}