]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix pg_identify_object_as_address() with event triggers
authorMichael Paquier <michael@paquier.xyz>
Wed, 28 Apr 2021 02:18:24 +0000 (11:18 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 28 Apr 2021 02:18:24 +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 fe9b05f529fcf623687ee3e9ea01d0b2f7881b66..967e055b4de826c5944b3220aacec5fc8c7a8abd 100644 (file)
@@ -5027,10 +5027,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));
@@ -5038,8 +5035,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 9d20fbb486fd0d5ee4ba8d960f6623cd8a3d6fd4..d265c44dfefc67d6681083b74c9c1faecfa678dc 100644 (file)
@@ -489,6 +489,23 @@ 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
+    e.evtname,
+    pg_describe_object('pg_event_trigger'::regclass, e.oid, 0) as descr,
+    b.type, b.object_names, b.object_args,
+    pg_identify_object(a.classid, a.objid, a.objsubid) as ident
+  FROM pg_event_trigger as e,
+    LATERAL pg_identify_object_as_address('pg_event_trigger'::regclass, e.oid, 0) as b,
+    LATERAL pg_get_object_address(b.type, b.object_names, b.object_args) as a
+  ORDER BY e.evtname;
+      evtname      |              descr              |     type      |    object_names     | object_args |                         ident                          
+-------------------+---------------------------------+---------------+---------------------+-------------+--------------------------------------------------------
+ end_rls_command   | event trigger end_rls_command   | event trigger | {end_rls_command}   | {}          | ("event trigger",,end_rls_command,end_rls_command)
+ sql_drop_command  | event trigger sql_drop_command  | event trigger | {sql_drop_command}  | {}          | ("event trigger",,sql_drop_command,sql_drop_command)
+ start_rls_command | event trigger start_rls_command | event trigger | {start_rls_command} | {}          | ("event trigger",,start_rls_command,start_rls_command)
+(3 rows)
+
 DROP EVENT TRIGGER start_rls_command;
 DROP EVENT TRIGGER end_rls_command;
 DROP EVENT TRIGGER sql_drop_command;
index e77e25dceeeb3237a12a6d306bcb788aaaa97a8e..3e0146444651ed2e5d8e25b5eca4250d87162854 100644 (file)
@@ -399,6 +399,17 @@ 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
+    e.evtname,
+    pg_describe_object('pg_event_trigger'::regclass, e.oid, 0) as descr,
+    b.type, b.object_names, b.object_args,
+    pg_identify_object(a.classid, a.objid, a.objsubid) as ident
+  FROM pg_event_trigger as e,
+    LATERAL pg_identify_object_as_address('pg_event_trigger'::regclass, e.oid, 0) as b,
+    LATERAL pg_get_object_address(b.type, b.object_names, b.object_args) as a
+  ORDER BY e.evtname;
+
 DROP EVENT TRIGGER start_rls_command;
 DROP EVENT TRIGGER end_rls_command;
 DROP EVENT TRIGGER sql_drop_command;