Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3753a16

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 99867e7 commit 3753a16

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
@@ -243,7 +243,8 @@ get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
243243
* Caller must have done permissions checks etc. already.
244244
*/
245245
static ObjectAddress
246-
CreateOpFamily(const char *amname, const char *opfname, Oid namespaceoid, Oid amoid)
246+
CreateOpFamily(CreateOpFamilyStmt *stmt, const char *opfname,
247+
Oid namespaceoid, Oid amoid)
247248
{
248249
Oid opfamilyoid;
249250
Relation rel;
@@ -267,7 +268,7 @@ CreateOpFamily(const char *amname, const char *opfname, Oid namespaceoid, Oid am
267268
ereport(ERROR,
268269
(errcode(ERRCODE_DUPLICATE_OBJECT),
269270
errmsg("operator family \"%s\" for access method \"%s\" already exists",
270-
opfname, amname)));
271+
opfname, stmt->amname)));
271272

272273
/*
273274
* Okay, let's create the pg_opfamily entry.
@@ -315,6 +316,10 @@ CreateOpFamily(const char *amname, const char *opfname, Oid namespaceoid, Oid am
315316
/* dependency on extension */
316317
recordDependencyOnCurrentExtension(&myself, false);
317318

319+
/* Report the new operator family to possibly interested event triggers */
320+
EventTriggerCollectSimpleCommand(myself, InvalidObjectAddress,
321+
(Node *) stmt);
322+
318323
/* Post creation hook for new operator family */
319324
InvokeObjectPostCreateHook(OperatorFamilyRelationId, opfamilyoid, 0);
320325

@@ -450,13 +455,17 @@ DefineOpClass(CreateOpClassStmt *stmt)
450455
}
451456
else
452457
{
458+
CreateOpFamilyStmt *opfstmt;
453459
ObjectAddress tmpAddr;
454460

461+
opfstmt = makeNode(CreateOpFamilyStmt);
462+
opfstmt->opfamilyname = stmt->opclassname;
463+
opfstmt->amname = stmt->amname;
464+
455465
/*
456466
* Create it ... again no need for more permissions ...
457467
*/
458-
tmpAddr = CreateOpFamily(stmt->amname, opcname,
459-
namespaceoid, amoid);
468+
tmpAddr = CreateOpFamily(opfstmt, opcname, namespaceoid, amoid);
460469
opfamilyoid = tmpAddr.objectId;
461470
}
462471
}
@@ -761,7 +770,7 @@ DefineOpFamily(CreateOpFamilyStmt *stmt)
761770
errmsg("must be superuser to create an operator family")));
762771

763772
/* Insert pg_opfamily catalog entry */
764-
return CreateOpFamily(stmt->amname, opfname, namespaceoid, amoid);
773+
return CreateOpFamily(stmt, opfname, namespaceoid, amoid);
765774
}
766775

767776

src/backend/tcop/utility.c

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

17141714
case T_CreateOpFamilyStmt:
17151715
address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
1716+
1717+
/*
1718+
* DefineOpFamily calls EventTriggerCollectSimpleCommand
1719+
* directly.
1720+
*/
1721+
commandCollected = true;
17161722
break;
17171723

17181724
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
@@ -478,6 +478,11 @@ NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_10_15
478478
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_15_20 name={evttrig,part_15_20} args={}
479479
DROP TABLE a_temp_tbl;
480480
NOTICE: NORMAL: orig=t normal=f istemp=t type=table identity=pg_temp.a_temp_tbl name={pg_temp,a_temp_tbl} args={}
481+
-- CREATE OPERATOR CLASS without FAMILY clause should report
482+
-- both CREATE OPERATOR FAMILY and CREATE OPERATOR CLASS
483+
CREATE OPERATOR CLASS evttrigopclass FOR TYPE int USING btree AS STORAGE int;
484+
NOTICE: END: command_tag=CREATE OPERATOR FAMILY type=operator family identity=public.evttrigopclass USING btree
485+
NOTICE: END: command_tag=CREATE OPERATOR CLASS type=operator class identity=public.evttrigopclass USING btree
481486
DROP EVENT TRIGGER regress_event_trigger_report_dropped;
482487
DROP EVENT TRIGGER regress_event_trigger_report_end;
483488
-- 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
@@ -339,6 +339,10 @@ DROP INDEX evttrig.one_idx;
339339
DROP SCHEMA evttrig CASCADE;
340340
DROP TABLE a_temp_tbl;
341341

342+
-- CREATE OPERATOR CLASS without FAMILY clause should report
343+
-- both CREATE OPERATOR FAMILY and CREATE OPERATOR CLASS
344+
CREATE OPERATOR CLASS evttrigopclass FOR TYPE int USING btree AS STORAGE int;
345+
342346
DROP EVENT TRIGGER regress_event_trigger_report_dropped;
343347
DROP EVENT TRIGGER regress_event_trigger_report_end;
344348

0 commit comments

Comments
 (0)