Skip to content

Commit 65158f4

Browse files
committed
Remove small inefficiency in ExecARDeleteTriggers/ExecARUpdateTriggers.
Whilst poking at nodeModifyTable.c, I chanced to notice that while its calls to ExecBR*Triggers and ExecIR*Triggers are protected by tests to see if there are any relevant triggers to fire, its calls to ExecAR*Triggers are not; the latter functions do the equivalent tests themselves. This seems possibly reasonable given the more complex conditions involved, but what's less reasonable is that the ExecAR* functions aren't careful to do no work when there is no work to be done. ExecARInsertTriggers gets this right, but the other two will both force creation of a slot that the query may have no use for. ExecARUpdateTriggers additionally performed a usually-useless ExecClearTuple() on that slot. This is probably all pretty microscopic in real workloads, but a cycle shaved is a cycle earned.
1 parent 9ee7d53 commit 65158f4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/backend/commands/trigger.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,11 +2546,12 @@ ExecARDeleteTriggers(EState *estate, ResultRelInfo *relinfo,
25462546
TransitionCaptureState *transition_capture)
25472547
{
25482548
TriggerDesc *trigdesc = relinfo->ri_TrigDesc;
2549-
TupleTableSlot *slot = ExecGetTriggerOldSlot(estate, relinfo);
25502549

25512550
if ((trigdesc && trigdesc->trig_delete_after_row) ||
25522551
(transition_capture && transition_capture->tcs_delete_old_table))
25532552
{
2553+
TupleTableSlot *slot = ExecGetTriggerOldSlot(estate, relinfo);
2554+
25542555
Assert(HeapTupleIsValid(fdw_trigtuple) ^ ItemPointerIsValid(tupleid));
25552556
if (fdw_trigtuple == NULL)
25562557
GetTupleForTrigger(estate,
@@ -2829,9 +2830,6 @@ ExecARUpdateTriggers(EState *estate, ResultRelInfo *relinfo,
28292830
TransitionCaptureState *transition_capture)
28302831
{
28312832
TriggerDesc *trigdesc = relinfo->ri_TrigDesc;
2832-
TupleTableSlot *oldslot = ExecGetTriggerOldSlot(estate, relinfo);
2833-
2834-
ExecClearTuple(oldslot);
28352833

28362834
if ((trigdesc && trigdesc->trig_update_after_row) ||
28372835
(transition_capture &&
@@ -2844,6 +2842,8 @@ ExecARUpdateTriggers(EState *estate, ResultRelInfo *relinfo,
28442842
* separately for DELETE and INSERT to capture transition table rows.
28452843
* In such case, either old tuple or new tuple can be NULL.
28462844
*/
2845+
TupleTableSlot *oldslot = ExecGetTriggerOldSlot(estate, relinfo);
2846+
28472847
if (fdw_trigtuple == NULL && ItemPointerIsValid(tupleid))
28482848
GetTupleForTrigger(estate,
28492849
NULL,
@@ -2854,6 +2854,8 @@ ExecARUpdateTriggers(EState *estate, ResultRelInfo *relinfo,
28542854
NULL);
28552855
else if (fdw_trigtuple != NULL)
28562856
ExecForceStoreHeapTuple(fdw_trigtuple, oldslot, false);
2857+
else
2858+
ExecClearTuple(oldslot);
28572859

28582860
AfterTriggerSaveEvent(estate, relinfo, TRIGGER_EVENT_UPDATE,
28592861
true, oldslot, newslot, recheckIndexes,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy