aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2022-05-20 18:52:55 +0200
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2022-05-20 18:52:55 +0200
commit4492e73a66bf88dc7d556a29fde476ba1deb69cb (patch)
tree1bce8b7bef762f1d519dab23d815107c1e8fbd31
parentac78cec9811b88e63854406a938f1de6673f3047 (diff)
downloadpostgresql-4492e73a66bf88dc7d556a29fde476ba1deb69cb.tar.gz
postgresql-4492e73a66bf88dc7d556a29fde476ba1deb69cb.zip
Fix DDL deparse of CREATE OPERATOR CLASS
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 <sawada.mshk@gmail.com> Reported-by: Leslie LEMAIRE <leslie.lemaire@developpement-durable.gouv.fr> Reviewed-by: Amit Kapila <amit.kapila16@gmail.com> Reviewed-by: Michael Paquiër <michael@paquier.xyz> Discussion: https://postgr.es/m/f74d69e151b22171e8829551b1159e77@developpement-durable.gouv.fr
-rw-r--r--src/backend/commands/opclasscmds.c19
-rw-r--r--src/backend/tcop/utility.c6
-rw-r--r--src/test/modules/test_ddl_deparse/expected/opfamily.out1
-rw-r--r--src/test/regress/expected/event_trigger.out5
-rw-r--r--src/test/regress/sql/event_trigger.sql4
5 files changed, 30 insertions, 5 deletions
diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c
index 6a1ccdeb826..2705b34a42d 100644
--- a/src/backend/commands/opclasscmds.c
+++ b/src/backend/commands/opclasscmds.c
@@ -243,7 +243,8 @@ get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
* Caller must have done permissions checks etc. already.
*/
static ObjectAddress
-CreateOpFamily(const char *amname, const char *opfname, Oid namespaceoid, Oid amoid)
+CreateOpFamily(CreateOpFamilyStmt *stmt, const char *opfname,
+ Oid namespaceoid, Oid amoid)
{
Oid opfamilyoid;
Relation rel;
@@ -267,7 +268,7 @@ CreateOpFamily(const char *amname, const char *opfname, Oid namespaceoid, Oid am
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.
@@ -315,6 +316,10 @@ CreateOpFamily(const char *amname, const char *opfname, Oid namespaceoid, Oid am
/* 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);
@@ -448,13 +453,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;
}
}
@@ -760,7 +769,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);
}
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index e22ddb4427c..071365486db 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -1597,6 +1597,12 @@ ProcessUtilitySlow(ParseState *pstate,
case T_CreateOpFamilyStmt:
address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
+
+ /*
+ * DefineOpFamily calls EventTriggerCollectSimpleCommand
+ * directly.
+ */
+ commandCollected = true;
break;
case T_CreateTransformStmt:
diff --git a/src/test/modules/test_ddl_deparse/expected/opfamily.out b/src/test/modules/test_ddl_deparse/expected/opfamily.out
index 14bd6037cdf..c7e3a23ef70 100644
--- a/src/test/modules/test_ddl_deparse/expected/opfamily.out
+++ b/src/test/modules/test_ddl_deparse/expected/opfamily.out
@@ -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
diff --git a/src/test/regress/expected/event_trigger.out b/src/test/regress/expected/event_trigger.out
index 041de458776..4af4b90eab7 100644
--- a/src/test/regress/expected/event_trigger.out
+++ b/src/test/regress/expected/event_trigger.out
@@ -478,6 +478,11 @@ 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;
+NOTICE: END: command_tag=CREATE OPERATOR FAMILY type=operator family identity=public.evttrigopclass USING btree
+NOTICE: END: command_tag=CREATE OPERATOR CLASS type=operator class identity=public.evttrigopclass USING btree
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
diff --git a/src/test/regress/sql/event_trigger.sql b/src/test/regress/sql/event_trigger.sql
index 7572a2280e6..e9dd0b47711 100644
--- a/src/test/regress/sql/event_trigger.sql
+++ b/src/test/regress/sql/event_trigger.sql
@@ -339,6 +339,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;