Fix pg_identify_object_as_address() with event triggers
authorMichael Paquier <[email protected]>
Wed, 28 Apr 2021 02:18:33 +0000 (11:18 +0900)
committerMichael Paquier <[email protected]>
Wed, 28 Apr 2021 02:18:33 +0000 (11:18 +0900)
Attempting to use this function with event triggers failed, as, since
its introduction in a676201, this code has never associated an object
name with event triggers.  This addresses the failure by adding the
event trigger name to the set defining its object address.

Note that regression tests are added within event_trigger and not
object_address to avoid issues with concurrent connections in parallel
schedules.

Author: Joel Jacobson
Discussion: https://postgr.es/m/3c905e77-a026-46ae-8835-c3f6cd1d24c8@www.fastmail.com
Backpatch-through: 9.6

src/backend/catalog/objectaddress.c
src/test/regress/expected/event_trigger.out
src/test/regress/sql/event_trigger.sql

index c3f21d371af189dcee5bcde020cddb83928a5163..f9a8270f9592372e260b1a53972c90a7f3396f62 100644 (file)
@@ -4673,10 +4673,7 @@ getObjectIdentityParts(const ObjectAddress *object,
            {
                HeapTuple   tup;
                Form_pg_event_trigger trigForm;
-
-               /* no objname support here */
-               if (objname)
-                   *objname = NIL;
+               char       *evtname;
 
                tup = SearchSysCache1(EVENTTRIGGEROID,
                                      ObjectIdGetDatum(object->objectId));
@@ -4684,8 +4681,10 @@ getObjectIdentityParts(const ObjectAddress *object,
                    elog(ERROR, "cache lookup failed for event trigger %u",
                         object->objectId);
                trigForm = (Form_pg_event_trigger) GETSTRUCT(tup);
-               appendStringInfoString(&buffer,
-                              quote_identifier(NameStr(trigForm->evtname)));
+               evtname = NameStr(trigForm->evtname);
+               appendStringInfoString(&buffer, quote_identifier(evtname));
+               if (objname)
+                   *objname = list_make1(evtname);
                ReleaseSysCache(tup);
                break;
            }
index f602163027b930dc1953239c2d74c26796954474..88c5ec3c8edac62adb4ed58237d7d51e38dfe065 100644 (file)
@@ -458,6 +458,21 @@ DROP POLICY p2 ON event_trigger_test;
 NOTICE:  DROP POLICY - ddl_command_start
 NOTICE:  DROP POLICY - sql_drop
 NOTICE:  DROP POLICY - ddl_command_end
+-- Check the object addresses of all the event triggers.
+SELECT
+    evtname,
+    pg_describe_object('pg_event_trigger'::regclass, oid, 0),
+    pg_identify_object('pg_event_trigger'::regclass, oid, 0),
+    pg_identify_object_as_address('pg_event_trigger'::regclass, oid, 0)
+  FROM pg_event_trigger
+  ORDER BY evtname;
+      evtname      |       pg_describe_object        |                   pg_identify_object                   |      pg_identify_object_as_address       
+-------------------+---------------------------------+--------------------------------------------------------+------------------------------------------
+ end_rls_command   | event trigger end_rls_command   | ("event trigger",,end_rls_command,end_rls_command)     | ("event trigger",{end_rls_command},{})
+ sql_drop_command  | event trigger sql_drop_command  | ("event trigger",,sql_drop_command,sql_drop_command)   | ("event trigger",{sql_drop_command},{})
+ start_rls_command | event trigger start_rls_command | ("event trigger",,start_rls_command,start_rls_command) | ("event trigger",{start_rls_command},{})
+(3 rows)
+
 DROP EVENT TRIGGER start_rls_command;
 DROP EVENT TRIGGER end_rls_command;
 DROP EVENT TRIGGER sql_drop_command;
index c8eb747d92d05b4df48a123fa17e6f9572d560b9..4453843fa552793ef7bdaa449a9cdb230b01538e 100644 (file)
@@ -378,6 +378,15 @@ ALTER POLICY p1 ON event_trigger_test USING (TRUE);
 ALTER POLICY p1 ON event_trigger_test RENAME TO p2;
 DROP POLICY p2 ON event_trigger_test;
 
+-- Check the object addresses of all the event triggers.
+SELECT
+    evtname,
+    pg_describe_object('pg_event_trigger'::regclass, oid, 0),
+    pg_identify_object('pg_event_trigger'::regclass, oid, 0),
+    pg_identify_object_as_address('pg_event_trigger'::regclass, oid, 0)
+  FROM pg_event_trigger
+  ORDER BY evtname;
+
 DROP EVENT TRIGGER start_rls_command;
 DROP EVENT TRIGGER end_rls_command;
 DROP EVENT TRIGGER sql_drop_command;