Skip to content

Commit 8514bf4

Browse files
committed
Remove duplicate code in DefineOpFamily().
The code was probably meant to be this way all along, since the subroutine CreateOpFamily previously had only one caller. But it wasn't. KaiGai Kohei
1 parent 25be9b1 commit 8514bf4

File tree

1 file changed

+4
-65
lines changed

1 file changed

+4
-65
lines changed

src/backend/commands/opclasscmds.c

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.68 2010/07/06 19:18:56 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.69 2010/07/16 00:13:23 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -640,16 +640,9 @@ DefineOpFamily(CreateOpFamilyStmt *stmt)
640640
{
641641
char *opfname; /* name of opfamily we're creating */
642642
Oid amoid, /* our AM's oid */
643-
namespaceoid, /* namespace to create opfamily in */
644-
opfamilyoid; /* oid of opfamily we create */
645-
Relation rel;
643+
namespaceoid; /* namespace to create opfamily in */
646644
HeapTuple tup;
647-
Datum values[Natts_pg_opfamily];
648-
bool nulls[Natts_pg_opfamily];
649645
AclResult aclresult;
650-
NameData opfName;
651-
ObjectAddress myself,
652-
referenced;
653646

654647
/* Convert list of names to a name and namespace */
655648
namespaceoid = QualifiedNameGetCreationNamespace(stmt->opfamilyname,
@@ -678,68 +671,14 @@ DefineOpFamily(CreateOpFamilyStmt *stmt)
678671
/*
679672
* Currently, we require superuser privileges to create an opfamily. See
680673
* comments in DefineOpClass.
681-
*
682-
* XXX re-enable NOT_USED code sections below if you remove this test.
683674
*/
684675
if (!superuser())
685676
ereport(ERROR,
686677
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
687678
errmsg("must be superuser to create an operator family")));
688679

689-
rel = heap_open(OperatorFamilyRelationId, RowExclusiveLock);
690-
691-
/*
692-
* Make sure there is no existing opfamily of this name (this is just to
693-
* give a more friendly error message than "duplicate key").
694-
*/
695-
if (SearchSysCacheExists3(OPFAMILYAMNAMENSP,
696-
ObjectIdGetDatum(amoid),
697-
CStringGetDatum(opfname),
698-
ObjectIdGetDatum(namespaceoid)))
699-
ereport(ERROR,
700-
(errcode(ERRCODE_DUPLICATE_OBJECT),
701-
errmsg("operator family \"%s\" for access method \"%s\" already exists",
702-
opfname, stmt->amname)));
703-
704-
/*
705-
* Okay, let's create the pg_opfamily entry.
706-
*/
707-
memset(values, 0, sizeof(values));
708-
memset(nulls, false, sizeof(nulls));
709-
710-
values[Anum_pg_opfamily_opfmethod - 1] = ObjectIdGetDatum(amoid);
711-
namestrcpy(&opfName, opfname);
712-
values[Anum_pg_opfamily_opfname - 1] = NameGetDatum(&opfName);
713-
values[Anum_pg_opfamily_opfnamespace - 1] = ObjectIdGetDatum(namespaceoid);
714-
values[Anum_pg_opfamily_opfowner - 1] = ObjectIdGetDatum(GetUserId());
715-
716-
tup = heap_form_tuple(rel->rd_att, values, nulls);
717-
718-
opfamilyoid = simple_heap_insert(rel, tup);
719-
720-
CatalogUpdateIndexes(rel, tup);
721-
722-
heap_freetuple(tup);
723-
724-
/*
725-
* Create dependencies for the opfamily proper. Note: we do not create a
726-
* dependency link to the AM, because we don't currently support DROP
727-
* ACCESS METHOD.
728-
*/
729-
myself.classId = OperatorFamilyRelationId;
730-
myself.objectId = opfamilyoid;
731-
myself.objectSubId = 0;
732-
733-
/* dependency on namespace */
734-
referenced.classId = NamespaceRelationId;
735-
referenced.objectId = namespaceoid;
736-
referenced.objectSubId = 0;
737-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
738-
739-
/* dependency on owner */
740-
recordDependencyOnOwner(OperatorFamilyRelationId, opfamilyoid, GetUserId());
741-
742-
heap_close(rel, RowExclusiveLock);
680+
/* Insert pg_opfamily catalog entry */
681+
(void) CreateOpFamily(stmt->amname, opfname, namespaceoid, amoid);
743682
}
744683

745684

0 commit comments

Comments
 (0)