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

Function AfterTriggerPendingOnRel

src/backend/commands/trigger.c:5659–5703  ·  view source on GitHub ↗

---------- * AfterTriggerPendingOnRel() * Test to see if there are any pending after-trigger events for rel. * * This is used by TRUNCATE, CLUSTER, ALTER TABLE, etc to detect whether * it is unsafe to perform major surgery on a relation. Note that only * local pending events are examined. We assume that having exclusive lock * on a rel guarantees there are no unserviced events in other b

Source from the content-addressed store, hash-verified

5657 * ----------
5658 */
5659bool
5660AfterTriggerPendingOnRel(Oid relid)
5661{
5662 AfterTriggerEvent event;
5663 AfterTriggerEventChunk *chunk;
5664 int depth;
5665
5666 /* Scan queued events */
5667 for_each_event_chunk(event, chunk, afterTriggers.events)
5668 {
5669 AfterTriggerShared evtshared = GetTriggerSharedData(event);
5670
5671 /*
5672 * We can ignore completed events. (Even if a DONE flag is rolled
5673 * back by subxact abort, it's OK because the effects of the TRUNCATE
5674 * or whatever must get rolled back too.)
5675 */
5676 if (event->ate_flags & AFTER_TRIGGER_DONE)
5677 continue;
5678
5679 if (evtshared->ats_relid == relid)
5680 return true;
5681 }
5682
5683 /*
5684 * Also scan events queued by incomplete queries. This could only matter
5685 * if TRUNCATE/etc is executed by a function or trigger within an updating
5686 * query on the same relation, which is pretty perverse, but let's check.
5687 */
5688 for (depth = 0; depth <= afterTriggers.query_depth && depth < afterTriggers.maxquerydepth; depth++)
5689 {
5690 for_each_event_chunk(event, chunk, afterTriggers.query_stack[depth].events)
5691 {
5692 AfterTriggerShared evtshared = GetTriggerSharedData(event);
5693
5694 if (event->ate_flags & AFTER_TRIGGER_DONE)
5695 continue;
5696
5697 if (evtshared->ats_relid == relid)
5698 return true;
5699 }
5700 }
5701
5702 return false;
5703}
5704
5705
5706/* ----------

Callers 1

CheckTableNotInUseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected