Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70f70d7

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 <[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/[email protected]
1 parent fa51cc8 commit 70f70d7

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

src/backend/commands/opclasscmds.c

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

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

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

@@ -438,13 +443,17 @@ DefineOpClass(CreateOpClassStmt *stmt)
438443
}
439444
else
440445
{
446+
CreateOpFamilyStmt *opfstmt;
441447
ObjectAddress tmpAddr;
442448

449+
opfstmt = makeNode(CreateOpFamilyStmt);
450+
opfstmt->opfamilyname = stmt->opclassname;
451+
opfstmt->amname = stmt->amname;
452+
443453
/*
444454
* Create it ... again no need for more permissions ...
445455
*/
446-
tmpAddr = CreateOpFamily(stmt->amname, opcname,
447-
namespaceoid, amoid);
456+
tmpAddr = CreateOpFamily(opfstmt, opcname, namespaceoid, amoid);
448457
opfamilyoid = tmpAddr.objectId;
449458
}
450459
}
@@ -747,7 +756,7 @@ DefineOpFamily(CreateOpFamilyStmt *stmt)
747756
errmsg("must be superuser to create an operator family")));
748757

749758
/* Insert pg_opfamily catalog entry */
750-
return CreateOpFamily(stmt->amname, opfname, namespaceoid, amoid);
759+
return CreateOpFamily(stmt, opfname, namespaceoid, amoid);
751760
}
752761

753762

src/backend/tcop/utility.c

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

15591559
case T_CreateOpFamilyStmt:
15601560
address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
1561+
1562+
/*
1563+
* DefineOpFamily calls EventTriggerCollectSimpleCommand
1564+
* directly.
1565+
*/
1566+
commandCollected = true;
15611567
break;
15621568

15631569
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_10_15
424424
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_15_20 name={evttrig,part_15_20} args={}
425425
DROP TABLE a_temp_tbl;
426426
NOTICE: NORMAL: orig=t normal=f istemp=t type=table identity=pg_temp.a_temp_tbl name={pg_temp,a_temp_tbl} args={}
427+
-- CREATE OPERATOR CLASS without FAMILY clause should report
428+
-- both CREATE OPERATOR FAMILY and CREATE OPERATOR CLASS
429+
CREATE OPERATOR CLASS evttrigopclass FOR TYPE int USING btree AS STORAGE int;
427430
DROP EVENT TRIGGER regress_event_trigger_report_dropped;
428431
DROP EVENT TRIGGER regress_event_trigger_report_end;
429432
-- 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
@@ -309,6 +309,10 @@ DROP INDEX evttrig.one_idx;
309309
DROP SCHEMA evttrig CASCADE;
310310
DROP TABLE a_temp_tbl;
311311

312+
-- CREATE OPERATOR CLASS without FAMILY clause should report
313+
-- both CREATE OPERATOR FAMILY and CREATE OPERATOR CLASS
314+
CREATE OPERATOR CLASS evttrigopclass FOR TYPE int USING btree AS STORAGE int;
315+
312316
DROP EVENT TRIGGER regress_event_trigger_report_dropped;
313317
DROP EVENT TRIGGER regress_event_trigger_report_end;
314318

0 commit comments

Comments
 (0)