8000 Fix DDL deparse of CREATE OPERATOR CLASS · postgres/postgres@6c6ea6e · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c6ea6e

Browse files
committed
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
1 parent daf015f commit 6c6ea6e

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

src/backend/commands/opclasscmds.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
239239
* Caller must have done permissions checks etc. already.
240240
*/
241241
static ObjectAddress
242-
CreateOpFamily(const char *amname, const char *opfname, Oid namespaceoid, Oid amoid)
242+
CreateOpFamily(CreateOpFamilyStmt *stmt, const char *opfname,
243+
Oid namespaceoid, Oid amoid)
243244
{
244245
Oid opfamilyoid;
245246
Relation rel;
@@ -263,7 +264,7 @@ CreateOpFamily(const char *amname, const char *opfname, Oid namespaceoid, Oid am
263264
ereport(ERROR,
264265
(errcode(ERRCODE_DUPLICATE_OBJECT),
265266
errmsg("operator family \"%s\" for access method \"%s\" already exists",
266-
opfname, amname)));
267+
opfname, stmt->amname)));
267268

268269
/*
269270
* Okay, let's create the pg_opfamily entry.
@@ -308,6 +309,10 @@ CreateOpFamily(const char *amname, const char *opfname, Oid namespaceoid, Oid am
308309
/* dependency on extension */
309310
recordDependencyOnCurrentExtension(&myself, false);
310311

312+
/* Report the new operator family to possibly interested event triggers */
313+
EventTriggerCollectSimpleCommand(myself, InvalidObjectAddress,
314+
(Node *) stmt);
315+
311316
/* Post creation hook for new operator family */
312317
InvokeObjectPostCreateHook(OperatorFamilyRelationId, opfamilyoid, 0);
313318

@@ -439,13 +444,17 @@ DefineOpClass(CreateOpClassStmt *stmt)
439444
}
440445
else
441446
{
447+
CreateOpFamilyStmt *opfstmt;
442448
ObjectAddress tmpAddr;
443449

450+
opfstmt = makeNode(CreateOpFamilyStmt);
451+
opfstmt->opfamilyname = stmt->opclassname;
452+
opfstmt->amname = stmt->amname;
453+
444454
/*
445455
* Create it ... again no need for more permissions ...
446456
*/
447-
tmpAddr = CreateOpFamily(stmt->amname, opcname,
448-
namespaceoid, amoid);
457+
tmpAddr = CreateOpFamily(opfstmt, opcname, namespaceoid, amoid);
449458
opfamilyoid = tmpAddr.objectId;
450459
}
451460
}
@@ -748,7 +757,7 @@ DefineOpFamily(CreateOpFamilyStmt *stmt)
748757
errmsg("must be superuser to create an operator family")));
749758

750759
/* Insert pg_opfamily catalog entry */
751-
return CreateOpFamily(stmt->amname, opfname, namespaceoid, amoid);
760+
return CreateOpFamily(stmt, opfname, namespaceoid, amoid);
752761
}
753762

754763

src/backend/tcop/utility.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,12 @@ ProcessUtilitySlow(ParseState *pstate,
15921592

15931593
case T_CreateOpFamilyStmt:
15941594
address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
1595+
1596+
/*
1597+
* DefineOpFamily calls EventTriggerCollectSimpleCommand
1598+
* directly.
1599+
*/
1600+
commandCollected = true;
15951601
break;
15961602

15971603
case T_CreateTransformStmt:

src/test/modules/test_ddl_deparse/expected/opfamily.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ NOTICE: DDL test: type simple, tag CREATE OPERATOR
6464
create operator class ctype_hash_ops
6565
default for type ctype using hash as
6666
operator 1 =(ctype, ctype);
67+
NOTICE: DDL test: type simple, tag CREATE OPERATOR FAMILY
6768
NOTICE: DDL test: type create operator class, tag CREATE OPERATOR CLASS

src/test/regress/expected/event_trigger.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,11 @@ NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_10_15
443443
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_15_20 name={evttrig,part_15_20} args={}
444444
DROP TABLE a_temp_tbl;
445445
NOTICE: NORMAL: orig=t normal=f istemp=t type=table identity=pg_temp.a_temp_tbl name={pg_temp,a_temp_tbl} args={}
446+
-- CREATE OPERATOR CLASS without FAMILY clause should report
447+
-- both CREATE OPERATOR FAMILY and CREATE OPERATOR CLASS
448+
CREATE OPERATOR CLASS evttrigopclass FOR TYPE int USING btree AS STORAGE int;
449+
NOTICE: END: command_tag=CREATE OPERATOR FAMILY type=operator family identity=public.evttrigopclass USING btree
450+
NOTICE: END: command_tag=CREATE OPERATOR CLASS type=operator class identity=public.evttrigopclass USING btree
446451
DROP EVENT TRIGGER regress_event_trigger_report_dropped;
447452
DROP EVENT TRIGGER regress_event_trigger_report_end;
448453
-- only allowed from within an event trigger function, should fail

src/test/regress/sql/event_trigger.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ DROP INDEX evttrig.one_idx;
320320
DROP SCHEMA evttrig CASCADE;
321321
DROP TABLE a_temp_tbl;
322322

323+
-- CREATE OPERATOR CLASS without FAMILY clause should report
324+
-- both CREATE OPERATOR FAMILY and CREATE OPERATOR CLASS
325+
CREATE OPERATOR CLASS evttrigopclass FOR TYPE int USING btree AS STORAGE int;
326+
323327
DROP EVENT TRIGGER regress_event_trigger_report_dropped;
324328
DROP EVENT TRIGGER regress_event_trigger_report_end;
325329

0 commit comments

Comments
 (0)
0