if (!IsUnderPostmaster)
return;
+ /*
+ * Also do nothing if our state isn't set up, which it won't be if there
+ * weren't any relevant event triggers at the start of the current DDL
+ * command. This test might therefore seem optional, but it's important
+ * because EventTriggerCommonSetup might find triggers that didn't exist
+ * at the time the command started. Although this function itself
+ * wouldn't crash, the event trigger functions would presumably call
+ * pg_event_trigger_ddl_commands which would fail. Better to do nothing
+ * until the next command.
+ */
+ if (!currentEventTriggerState)
+ return;
+
runlist = EventTriggerCommonSetup(parsetree,
EVT_DDLCommandEnd, "ddl_command_end",
&trigdata);
&trigdata);
/*
- * Nothing to do if run list is empty. Note this shouldn't happen,
+ * Nothing to do if run list is empty. Note this typically can't happen,
* because if there are no sql_drop events, then objects-to-drop wouldn't
* have been collected in the first place and we would have quit above.
+ * But it could occur if event triggers were dropped partway through.
*/
if (runlist == NIL)
return;
List *runlist;
EventTriggerData trigdata;
- elog(DEBUG1, "EventTriggerTableRewrite(%u)", tableOid);
-
/*
* Event Triggers are completely disabled in standalone mode. There are
* (at least) two reasons for this:
if (!IsUnderPostmaster)
return;
+ /*
+ * Also do nothing if our state isn't set up, which it won't be if there
+ * weren't any relevant event triggers at the start of the current DDL
+ * command. This test might therefore seem optional, but it's
+ * *necessary*, because EventTriggerCommonSetup might find triggers that
+ * didn't exist at the time the command started.
+ */
+ if (!currentEventTriggerState)
+ return;
+
runlist = EventTriggerCommonSetup(parsetree,
EVT_TableRewrite,
"table_rewrite",