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

Function EventTriggerTableRewrite

src/backend/commands/event_trigger.c:807–867  ·  view source on GitHub ↗

* Fire table_rewrite triggers. */

Source from the content-addressed store, hash-verified

805 * Fire table_rewrite triggers.
806 */
807void
808EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason)
809{
810 List *runlist;
811 EventTriggerData trigdata;
812
813 /*
814 * See EventTriggerDDLCommandStart for a discussion about why event
815 * triggers are disabled in single user mode.
816 */
817 if (!IsUnderPostmaster)
818 return;
819
820 /*
821 * Also do nothing if our state isn't set up, which it won't be if there
822 * weren't any relevant event triggers at the start of the current DDL
823 * command. This test might therefore seem optional, but it's
824 * *necessary*, because EventTriggerCommonSetup might find triggers that
825 * didn't exist at the time the command started.
826 */
827 if (!currentEventTriggerState)
828 return;
829
830 runlist = EventTriggerCommonSetup(parsetree,
831 EVT_TableRewrite,
832 "table_rewrite",
833 &trigdata);
834 if (runlist == NIL)
835 return;
836
837 /*
838 * Make sure pg_event_trigger_table_rewrite_oid only works when running
839 * these triggers. Use PG_TRY to ensure table_rewrite_oid is reset even
840 * when one trigger fails. (This is perhaps not necessary, as the
841 * currentState variable will be removed shortly by our caller, but it
842 * seems better to play safe.)
843 */
844 currentEventTriggerState->table_rewrite_oid = tableOid;
845 currentEventTriggerState->table_rewrite_reason = reason;
846
847 /* Run the triggers. */
848 PG_TRY();
849 {
850 EventTriggerInvoke(runlist, &trigdata);
851 }
852 PG_FINALLY();
853 {
854 currentEventTriggerState->table_rewrite_oid = InvalidOid;
855 currentEventTriggerState->table_rewrite_reason = 0;
856 }
857 PG_END_TRY();
858
859 /* Cleanup. */
860 list_free(runlist);
861
862 /*
863 * Make sure anything the event triggers did will be visible to the main
864 * command.

Callers 1

ATRewriteTablesFunction · 0.85

Calls 4

EventTriggerCommonSetupFunction · 0.85
EventTriggerInvokeFunction · 0.85
CommandCounterIncrementFunction · 0.85
list_freeFunction · 0.50

Tested by

no test coverage detected