MCPcopy Create free account
hub / github.com/apache/cloudberry / ExecIRInsertTriggers

Function ExecIRInsertTriggers

src/backend/commands/trigger.c:2427–2486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2425}
2426
2427bool
2428ExecIRInsertTriggers(EState *estate, ResultRelInfo *relinfo,
2429 TupleTableSlot *slot)
2430{
2431 TriggerDesc *trigdesc = relinfo->ri_TrigDesc;
2432 HeapTuple newtuple = NULL;
2433 bool should_free;
2434 TriggerData LocTriggerData = {0};
2435 int i;
2436
2437 LocTriggerData.type = T_TriggerData;
2438 LocTriggerData.tg_event = TRIGGER_EVENT_INSERT |
2439 TRIGGER_EVENT_ROW |
2440 TRIGGER_EVENT_INSTEAD;
2441 LocTriggerData.tg_relation = relinfo->ri_RelationDesc;
2442 for (i = 0; i < trigdesc->numtriggers; i++)
2443 {
2444 Trigger *trigger = &trigdesc->triggers[i];
2445 HeapTuple oldtuple;
2446
2447 if (!TRIGGER_TYPE_MATCHES(trigger->tgtype,
2448 TRIGGER_TYPE_ROW,
2449 TRIGGER_TYPE_INSTEAD,
2450 TRIGGER_TYPE_INSERT))
2451 continue;
2452 if (!TriggerEnabled(estate, relinfo, trigger, LocTriggerData.tg_event,
2453 NULL, NULL, slot))
2454 continue;
2455
2456 if (!newtuple)
2457 newtuple = ExecFetchSlotHeapTuple(slot, true, &should_free);
2458
2459 LocTriggerData.tg_trigslot = slot;
2460 LocTriggerData.tg_trigtuple = oldtuple = newtuple;
2461 LocTriggerData.tg_trigger = trigger;
2462 newtuple = ExecCallTriggerFunc(&LocTriggerData,
2463 i,
2464 relinfo->ri_TrigFunctions,
2465 relinfo->ri_TrigInstrument,
2466 GetPerTupleMemoryContext(estate));
2467 if (newtuple == NULL)
2468 {
2469 if (should_free)
2470 heap_freetuple(oldtuple);
2471 return false; /* "do nothing" */
2472 }
2473 else if (newtuple != oldtuple)
2474 {
2475 ExecForceStoreHeapTuple(newtuple, slot, false);
2476
2477 if (should_free)
2478 heap_freetuple(oldtuple);
2479
2480 /* signal tuple should be re-fetched if used */
2481 newtuple = NULL;
2482 }
2483 }
2484

Callers 2

CopyFromFunction · 0.85
ExecInsertFunction · 0.85

Calls 5

TriggerEnabledFunction · 0.85
ExecFetchSlotHeapTupleFunction · 0.85
ExecCallTriggerFuncFunction · 0.85
heap_freetupleFunction · 0.85
ExecForceStoreHeapTupleFunction · 0.85

Tested by

no test coverage detected