aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/event_trigger.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands/event_trigger.c')
-rw-r--r--src/backend/commands/event_trigger.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c
index 549c7ea51d7..45baf7c13f0 100644
--- a/src/backend/commands/event_trigger.c
+++ b/src/backend/commands/event_trigger.c
@@ -836,6 +836,19 @@ EventTriggerDDLCommandEnd(Node *parsetree)
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);
@@ -887,9 +900,10 @@ EventTriggerSQLDrop(Node *parsetree)
&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;
@@ -936,8 +950,6 @@ EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason)
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:
@@ -957,6 +969,16 @@ EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason)
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",