Fix DDL deparse of CREATE OPERATOR CLASS
authorAlvaro Herrera <[email protected]>
Fri, 20 May 2022 16:52:55 +0000 (18:52 +0200)
committerAlvaro Herrera <[email protected]>
Fri, 20 May 2022 16:52:55 +0000 (18:52 +0200)
When an implicit operator family is created, it wasn't getting reported.
Make it do so.

This has always been missing.  Backpatch to 10.

Author: Masahiko Sawada <[email protected]>
Reported-by: Leslie LEMAIRE <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Reviewed-by: Michael Paquiër <[email protected]>
Discussion: https://postgr.es/m/f74d69e151b22171e8829551b1159e77@developpement-durable.gouv.fr

src/backend/commands/opclasscmds.c
src/backend/tcop/utility.c
src/test/modules/test_ddl_deparse/expected/opfamily.out
src/test/regress/expected/event_trigger.out
src/test/regress/sql/event_trigger.sql

index a31b1acb9c6c4ac0fdfdd4469d0cf99be632583c..93a59d4c3794f5142d5efbb2aa771792e1e97f8e 100644 (file)
@@ -238,7 +238,8 @@ get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
  * Caller must have done permissions checks etc. already.
  */
 static ObjectAddress
-CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid)
+CreateOpFamily(CreateOpFamilyStmt *stmt, const char *opfname,
+              Oid namespaceoid, Oid amoid)
 {
    Oid         opfamilyoid;
    Relation    rel;
@@ -262,7 +263,7 @@ CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid)
        ereport(ERROR,
                (errcode(ERRCODE_DUPLICATE_OBJECT),
                 errmsg("operator family \"%s\" for access method \"%s\" already exists",
-                       opfname, amname)));
+                       opfname, stmt->amname)));
 
    /*
     * Okay, let's create the pg_opfamily entry.
@@ -307,6 +308,10 @@ CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid)
    /* dependency on extension */
    recordDependencyOnCurrentExtension(&myself, false);
 
+   /* Report the new operator family to possibly interested event triggers */
+   EventTriggerCollectSimpleCommand(myself, InvalidObjectAddress,
+                                    (Node *) stmt);
+
    /* Post creation hook for new operator family */
    InvokeObjectPostCreateHook(OperatorFamilyRelationId, opfamilyoid, 0);
 
@@ -438,13 +443,17 @@ DefineOpClass(CreateOpClassStmt *stmt)
        }
        else
        {
+           CreateOpFamilyStmt *opfstmt;
            ObjectAddress tmpAddr;
 
+           opfstmt = makeNode(CreateOpFamilyStmt);
+           opfstmt->opfamilyname = stmt->opclassname;
+           opfstmt->amname = stmt->amname;
+
            /*
             * Create it ... again no need for more permissions ...
             */
-           tmpAddr = CreateOpFamily(stmt->amname, opcname,
-                                    namespaceoid, amoid);
+           tmpAddr = CreateOpFamily(opfstmt, opcname, namespaceoid, amoid);
            opfamilyoid = tmpAddr.objectId;
        }
    }
@@ -747,7 +756,7 @@ DefineOpFamily(CreateOpFamilyStmt *stmt)
                 errmsg("must be superuser to create an operator family")));
 
    /* Insert pg_opfamily catalog entry */
-   return CreateOpFamily(stmt->amname, opfname, namespaceoid, amoid);
+   return CreateOpFamily(stmt, opfname, namespaceoid, amoid);
 }
 
 
index 185869d9fa84de932bfa9a5808dd14e485b7a640..3d3c1c9bfaca4a22651f883ff17f70554c1db83a 100644 (file)
@@ -1558,6 +1558,12 @@ ProcessUtilitySlow(ParseState *pstate,
 
            case T_CreateOpFamilyStmt:
                address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
+
+               /*
+                * DefineOpFamily calls EventTriggerCollectSimpleCommand
+                * directly.
+                */
+               commandCollected = true;
                break;
 
            case T_CreateTransformStmt:
index 14bd6037cdf61dd2a40272570264ba7b7cd02a94..c7e3a23ef70e03f9597f3eeec166c3b00050c62a 100644 (file)
@@ -64,4 +64,5 @@ NOTICE:  DDL test: type simple, tag CREATE OPERATOR
 create operator class ctype_hash_ops
   default for type ctype using hash as
   operator 1 =(ctype, ctype);
+NOTICE:  DDL test: type simple, tag CREATE OPERATOR FAMILY
 NOTICE:  DDL test: type create operator class, tag CREATE OPERATOR CLASS
index 36e81964d4735cec1d6d33a2f6b4f50d35a36d85..ed738f5490c6d31350600a078dbe719cca6bc9ac 100644 (file)
@@ -424,6 +424,9 @@ NOTICE:  NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_10_15
 NOTICE:  NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_15_20 name={evttrig,part_15_20} args={}
 DROP TABLE a_temp_tbl;
 NOTICE:  NORMAL: orig=t normal=f istemp=t type=table identity=pg_temp.a_temp_tbl name={pg_temp,a_temp_tbl} args={}
+-- CREATE OPERATOR CLASS without FAMILY clause should report
+-- both CREATE OPERATOR FAMILY and CREATE OPERATOR CLASS
+CREATE OPERATOR CLASS evttrigopclass FOR TYPE int USING btree AS STORAGE int;
 DROP EVENT TRIGGER regress_event_trigger_report_dropped;
 DROP EVENT TRIGGER regress_event_trigger_report_end;
 -- only allowed from within an event trigger function, should fail
index 9f1ab32a7c7d31be3bfc270b0a13958fa235d06b..aa013de012188414a6639f3edfb2430b1d82ee0a 100644 (file)
@@ -309,6 +309,10 @@ DROP INDEX evttrig.one_idx;
 DROP SCHEMA evttrig CASCADE;
 DROP TABLE a_temp_tbl;
 
+-- CREATE OPERATOR CLASS without FAMILY clause should report
+-- both CREATE OPERATOR FAMILY and CREATE OPERATOR CLASS
+CREATE OPERATOR CLASS evttrigopclass FOR TYPE int USING btree AS STORAGE int;
+
 DROP EVENT TRIGGER regress_event_trigger_report_dropped;
 DROP EVENT TRIGGER regress_event_trigger_report_end;