* Is trigger enabled to fire? */
| 3216 | * Is trigger enabled to fire? |
| 3217 | */ |
| 3218 | static bool |
| 3219 | TriggerEnabled(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; |
no test coverage detected