summaryrefslogtreecommitdiff
path: root/src/backend/commands/event_trigger.c
diff options
context:
space:
mode:
authorMichael Paquier2021-06-14 05:57:22 +0000
committerMichael Paquier2021-06-14 05:57:22 +0000
commit2d689babe3cb50dcb29f6ed595a61d56e518c0d8 (patch)
tree49069eccb9bbdfc801b5b27e5a23b3e55ab12bce /src/backend/commands/event_trigger.c
parentdbab0c07e5ba1f19a991da2d72972a8fe9a41bda (diff)
Improve handling of dropped objects in pg_event_trigger_ddl_commands()
An object found as dropped when digging into the list of objects returned by pg_event_trigger_ddl_commands() could cause a cache lookup error, as the calls grabbing for the object address and the type name would fail if the object was missing. Those lookup errors could be seen with combinations of ALTER TABLE sub-commands involving identity columns. The lookup logic is changed in this code path to get a behavior similar to any other SQL-callable function by ignoring objects that are not found, taking advantage of 2a10fdc. The back-branches are not changed, as they require this commit that is too invasive for stable branches. While on it, add test cases to exercise event triggers with identity columns, and stress more cases with the event ddl_command_end for relations. Author: Sven Klemm, Aleksander Alekseev, Michael Paquier Discussion: https://postgr.es/m/CAMCrgp2R1cEXU53iYKtW6yVEp2_yKUz+z=3-CTrYpPP+xryRtg@mail.gmail.com
Diffstat (limited to 'src/backend/commands/event_trigger.c')
-rw-r--r--src/backend/commands/event_trigger.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c
index 5bde507c752..9c31c9e7637 100644
--- a/src/backend/commands/event_trigger.c
+++ b/src/backend/commands/event_trigger.c
@@ -1936,8 +1936,19 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
else if (cmd->type == SCT_AlterTSConfig)
addr = cmd->d.atscfg.address;
- type = getObjectTypeDescription(&addr, false);
- identity = getObjectIdentity(&addr, false);
+ /*
+ * If an object was dropped in the same command we may end
+ * up in a situation where we generated a message but can
+ * no longer look for the object information, so skip it
+ * rather than failing. This can happen for example with
+ * some subcommand combinations of ALTER TABLE.
+ */
+ identity = getObjectIdentity(&addr, true);
+ if (identity == NULL)
+ continue;
+
+ /* The type can never be NULL. */
+ type = getObjectTypeDescription(&addr, true);
/*
* Obtain schema name, if any ("pg_temp" if a temp