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

Function TriggerEnabled

src/backend/commands/trigger.c:3218–3315  ·  view source on GitHub ↗

* Is trigger enabled to fire? */

Source from the content-addressed store, hash-verified

3216 * Is trigger enabled to fire?
3217 */
3218static bool
3219TriggerEnabled(EState *estate, ResultRelInfo *relinfo,
3220 Trigger *trigger, TriggerEvent event,
3221 Bitmapset *modifiedCols,
3222 TupleTableSlot *oldslot, TupleTableSlot *newslot)
3223{
3224 /* Check replication-role-dependent enable state */
3225 if (SessionReplicationRole == SESSION_REPLICATION_ROLE_REPLICA)
3226 {
3227 if (trigger->tgenabled == TRIGGER_FIRES_ON_ORIGIN ||
3228 trigger->tgenabled == TRIGGER_DISABLED)
3229 return false;
3230 }
3231 else /* ORIGIN or LOCAL role */
3232 {
3233 if (trigger->tgenabled == TRIGGER_FIRES_ON_REPLICA ||
3234 trigger->tgenabled == TRIGGER_DISABLED)
3235 return false;
3236 }
3237
3238 /*
3239 * Check for column-specific trigger (only possible for UPDATE, and in
3240 * fact we *must* ignore tgattr for other event types)
3241 */
3242 if (trigger->tgnattr > 0 && TRIGGER_FIRED_BY_UPDATE(event))
3243 {
3244 int i;
3245 bool modified;
3246
3247 modified = false;
3248 for (i = 0; i < trigger->tgnattr; i++)
3249 {
3250 if (bms_is_member(trigger->tgattr[i] - FirstLowInvalidHeapAttributeNumber,
3251 modifiedCols))
3252 {
3253 modified = true;
3254 break;
3255 }
3256 }
3257 if (!modified)
3258 return false;
3259 }
3260
3261 /* Check for WHEN clause */
3262 if (trigger->tgqual)
3263 {
3264 ExprState **predicate;
3265 ExprContext *econtext;
3266 MemoryContext oldContext;
3267 int i;
3268
3269 Assert(estate != NULL);
3270
3271 /*
3272 * trigger is an element of relinfo->ri_TrigDesc->triggers[]; find the
3273 * matching element of relinfo->ri_TrigWhenExprs[]
3274 */
3275 i = trigger - relinfo->ri_TrigDesc->triggers;

Callers 11

ExecBSInsertTriggersFunction · 0.85
ExecBRInsertTriggersFunction · 0.85
ExecIRInsertTriggersFunction · 0.85
ExecBSDeleteTriggersFunction · 0.85
ExecBRDeleteTriggersFunction · 0.85
ExecIRDeleteTriggersFunction · 0.85
ExecBSUpdateTriggersFunction · 0.85
ExecBRUpdateTriggersFunction · 0.85
ExecIRUpdateTriggersFunction · 0.85
ExecBSTruncateTriggersFunction · 0.85
AfterTriggerSaveEventFunction · 0.85

Calls 7

bms_is_memberFunction · 0.85
MemoryContextSwitchToFunction · 0.85
stringToNodeFunction · 0.85
ChangeVarNodesFunction · 0.85
make_ands_implicitFunction · 0.85
ExecPrepareQualFunction · 0.85
ExecQualFunction · 0.85

Tested by

no test coverage detected