mirror of
https://github.com/postgres/postgres.git
synced 2025-06-03 01:21:48 +03:00
Add get_opfamily_name() function
This refactors and simplifies various existing code to make use of the new function. Reviewed-by: Mark Dilger <mark.dilger@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/E72EAA49-354D-4C2E-8EB9-255197F55330@enterprisedb.com
This commit is contained in:
parent
a5709b5bb2
commit
43493cceda
@ -18,8 +18,8 @@
|
||||
#include "catalog/pg_amop.h"
|
||||
#include "catalog/pg_amproc.h"
|
||||
#include "catalog/pg_opclass.h"
|
||||
#include "catalog/pg_opfamily.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/regproc.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
@ -36,8 +36,6 @@ blvalidate(Oid opclassoid)
|
||||
Oid opcintype;
|
||||
Oid opckeytype;
|
||||
char *opclassname;
|
||||
HeapTuple familytup;
|
||||
Form_pg_opfamily familyform;
|
||||
char *opfamilyname;
|
||||
CatCList *proclist,
|
||||
*oprlist;
|
||||
@ -60,12 +58,7 @@ blvalidate(Oid opclassoid)
|
||||
opclassname = NameStr(classform->opcname);
|
||||
|
||||
/* Fetch opfamily information */
|
||||
familytup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfamilyoid));
|
||||
if (!HeapTupleIsValid(familytup))
|
||||
elog(ERROR, "cache lookup failed for operator family %u", opfamilyoid);
|
||||
familyform = (Form_pg_opfamily) GETSTRUCT(familytup);
|
||||
|
||||
opfamilyname = NameStr(familyform->opfname);
|
||||
opfamilyname = get_opfamily_name(opfamilyoid, false);
|
||||
|
||||
/* Fetch all operators and support functions of the opfamily */
|
||||
oprlist = SearchSysCacheList1(AMOPSTRATEGY, ObjectIdGetDatum(opfamilyoid));
|
||||
@ -216,7 +209,6 @@ blvalidate(Oid opclassoid)
|
||||
|
||||
ReleaseCatCacheList(proclist);
|
||||
ReleaseCatCacheList(oprlist);
|
||||
ReleaseSysCache(familytup);
|
||||
ReleaseSysCache(classtup);
|
||||
|
||||
return result;
|
||||
|
@ -19,9 +19,9 @@
|
||||
#include "catalog/pg_amop.h"
|
||||
#include "catalog/pg_amproc.h"
|
||||
#include "catalog/pg_opclass.h"
|
||||
#include "catalog/pg_opfamily.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/regproc.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
@ -42,8 +42,6 @@ brinvalidate(Oid opclassoid)
|
||||
Oid opfamilyoid;
|
||||
Oid opcintype;
|
||||
char *opclassname;
|
||||
HeapTuple familytup;
|
||||
Form_pg_opfamily familyform;
|
||||
char *opfamilyname;
|
||||
CatCList *proclist,
|
||||
*oprlist;
|
||||
@ -65,12 +63,7 @@ brinvalidate(Oid opclassoid)
|
||||
opclassname = NameStr(classform->opcname);
|
||||
|
||||
/* Fetch opfamily information */
|
||||
familytup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfamilyoid));
|
||||
if (!HeapTupleIsValid(familytup))
|
||||
elog(ERROR, "cache lookup failed for operator family %u", opfamilyoid);
|
||||
familyform = (Form_pg_opfamily) GETSTRUCT(familytup);
|
||||
|
||||
opfamilyname = NameStr(familyform->opfname);
|
||||
opfamilyname = get_opfamily_name(opfamilyoid, false);
|
||||
|
||||
/* Fetch all operators and support functions of the opfamily */
|
||||
oprlist = SearchSysCacheList1(AMOPSTRATEGY, ObjectIdGetDatum(opfamilyoid));
|
||||
@ -274,7 +267,6 @@ brinvalidate(Oid opclassoid)
|
||||
|
||||
ReleaseCatCacheList(proclist);
|
||||
ReleaseCatCacheList(oprlist);
|
||||
ReleaseSysCache(familytup);
|
||||
ReleaseSysCache(classtup);
|
||||
|
||||
return result;
|
||||
|
@ -19,8 +19,8 @@
|
||||
#include "catalog/pg_amop.h"
|
||||
#include "catalog/pg_amproc.h"
|
||||
#include "catalog/pg_opclass.h"
|
||||
#include "catalog/pg_opfamily.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/regproc.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
@ -37,8 +37,6 @@ ginvalidate(Oid opclassoid)
|
||||
Oid opcintype;
|
||||
Oid opckeytype;
|
||||
char *opclassname;
|
||||
HeapTuple familytup;
|
||||
Form_pg_opfamily familyform;
|
||||
char *opfamilyname;
|
||||
CatCList *proclist,
|
||||
*oprlist;
|
||||
@ -61,12 +59,7 @@ ginvalidate(Oid opclassoid)
|
||||
opclassname = NameStr(classform->opcname);
|
||||
|
||||
/* Fetch opfamily information */
|
||||
familytup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfamilyoid));
|
||||
if (!HeapTupleIsValid(familytup))
|
||||
elog(ERROR, "cache lookup failed for operator family %u", opfamilyoid);
|
||||
familyform = (Form_pg_opfamily) GETSTRUCT(familytup);
|
||||
|
||||
opfamilyname = NameStr(familyform->opfname);
|
||||
opfamilyname = get_opfamily_name(opfamilyoid, false);
|
||||
|
||||
/* Fetch all operators and support functions of the opfamily */
|
||||
oprlist = SearchSysCacheList1(AMOPSTRATEGY, ObjectIdGetDatum(opfamilyoid));
|
||||
@ -264,7 +257,6 @@ ginvalidate(Oid opclassoid)
|
||||
|
||||
ReleaseCatCacheList(proclist);
|
||||
ReleaseCatCacheList(oprlist);
|
||||
ReleaseSysCache(familytup);
|
||||
ReleaseSysCache(classtup);
|
||||
|
||||
return result;
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "catalog/pg_amop.h"
|
||||
#include "catalog/pg_amproc.h"
|
||||
#include "catalog/pg_opclass.h"
|
||||
#include "catalog/pg_opfamily.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/regproc.h"
|
||||
@ -39,8 +38,6 @@ gistvalidate(Oid opclassoid)
|
||||
Oid opcintype;
|
||||
Oid opckeytype;
|
||||
char *opclassname;
|
||||
HeapTuple familytup;
|
||||
Form_pg_opfamily familyform;
|
||||
char *opfamilyname;
|
||||
CatCList *proclist,
|
||||
*oprlist;
|
||||
@ -63,12 +60,7 @@ gistvalidate(Oid opclassoid)
|
||||
opclassname = NameStr(classform->opcname);
|
||||
|
||||
/* Fetch opfamily information */
|
||||
familytup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfamilyoid));
|
||||
if (!HeapTupleIsValid(familytup))
|
||||
elog(ERROR, "cache lookup failed for operator family %u", opfamilyoid);
|
||||
familyform = (Form_pg_opfamily) GETSTRUCT(familytup);
|
||||
|
||||
opfamilyname = NameStr(familyform->opfname);
|
||||
opfamilyname = get_opfamily_name(opfamilyoid, false);
|
||||
|
||||
/* Fetch all operators and support functions of the opfamily */
|
||||
oprlist = SearchSysCacheList1(AMOPSTRATEGY, ObjectIdGetDatum(opfamilyoid));
|
||||
@ -282,7 +274,6 @@ gistvalidate(Oid opclassoid)
|
||||
|
||||
ReleaseCatCacheList(proclist);
|
||||
ReleaseCatCacheList(oprlist);
|
||||
ReleaseSysCache(familytup);
|
||||
ReleaseSysCache(classtup);
|
||||
|
||||
return result;
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "catalog/pg_amop.h"
|
||||
#include "catalog/pg_amproc.h"
|
||||
#include "catalog/pg_opclass.h"
|
||||
#include "catalog/pg_opfamily.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/lsyscache.h"
|
||||
@ -46,8 +45,6 @@ hashvalidate(Oid opclassoid)
|
||||
Oid opfamilyoid;
|
||||
Oid opcintype;
|
||||
char *opclassname;
|
||||
HeapTuple familytup;
|
||||
Form_pg_opfamily familyform;
|
||||
char *opfamilyname;
|
||||
CatCList *proclist,
|
||||
*oprlist;
|
||||
@ -68,12 +65,7 @@ hashvalidate(Oid opclassoid)
|
||||
opclassname = NameStr(classform->opcname);
|
||||
|
||||
/* Fetch opfamily information */
|
||||
familytup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfamilyoid));
|
||||
if (!HeapTupleIsValid(familytup))
|
||||
elog(ERROR, "cache lookup failed for operator family %u", opfamilyoid);
|
||||
familyform = (Form_pg_opfamily) GETSTRUCT(familytup);
|
||||
|
||||
opfamilyname = NameStr(familyform->opfname);
|
||||
opfamilyname = get_opfamily_name(opfamilyoid, false);
|
||||
|
||||
/* Fetch all operators and support functions of the opfamily */
|
||||
oprlist = SearchSysCacheList1(AMOPSTRATEGY, ObjectIdGetDatum(opfamilyoid));
|
||||
@ -258,7 +250,6 @@ hashvalidate(Oid opclassoid)
|
||||
|
||||
ReleaseCatCacheList(proclist);
|
||||
ReleaseCatCacheList(oprlist);
|
||||
ReleaseSysCache(familytup);
|
||||
ReleaseSysCache(classtup);
|
||||
|
||||
return result;
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "catalog/pg_amop.h"
|
||||
#include "catalog/pg_amproc.h"
|
||||
#include "catalog/pg_opclass.h"
|
||||
#include "catalog/pg_opfamily.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/lsyscache.h"
|
||||
@ -46,8 +45,6 @@ btvalidate(Oid opclassoid)
|
||||
Oid opfamilyoid;
|
||||
Oid opcintype;
|
||||
char *opclassname;
|
||||
HeapTuple familytup;
|
||||
Form_pg_opfamily familyform;
|
||||
char *opfamilyname;
|
||||
CatCList *proclist,
|
||||
*oprlist;
|
||||
@ -69,12 +66,7 @@ btvalidate(Oid opclassoid)
|
||||
opclassname = NameStr(classform->opcname);
|
||||
|
||||
/* Fetch opfamily information */
|
||||
familytup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfamilyoid));
|
||||
if (!HeapTupleIsValid(familytup))
|
||||
elog(ERROR, "cache lookup failed for operator family %u", opfamilyoid);
|
||||
familyform = (Form_pg_opfamily) GETSTRUCT(familytup);
|
||||
|
||||
opfamilyname = NameStr(familyform->opfname);
|
||||
opfamilyname = get_opfamily_name(opfamilyoid, false);
|
||||
|
||||
/* Fetch all operators and support functions of the opfamily */
|
||||
oprlist = SearchSysCacheList1(AMOPSTRATEGY, ObjectIdGetDatum(opfamilyoid));
|
||||
@ -280,7 +272,6 @@ btvalidate(Oid opclassoid)
|
||||
|
||||
ReleaseCatCacheList(proclist);
|
||||
ReleaseCatCacheList(oprlist);
|
||||
ReleaseSysCache(familytup);
|
||||
ReleaseSysCache(classtup);
|
||||
|
||||
return result;
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "catalog/pg_amop.h"
|
||||
#include "catalog/pg_amproc.h"
|
||||
#include "catalog/pg_opclass.h"
|
||||
#include "catalog/pg_opfamily.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/lsyscache.h"
|
||||
@ -45,8 +44,6 @@ spgvalidate(Oid opclassoid)
|
||||
Oid opcintype;
|
||||
Oid opckeytype;
|
||||
char *opclassname;
|
||||
HeapTuple familytup;
|
||||
Form_pg_opfamily familyform;
|
||||
char *opfamilyname;
|
||||
CatCList *proclist,
|
||||
*oprlist;
|
||||
@ -72,12 +69,7 @@ spgvalidate(Oid opclassoid)
|
||||
opclassname = NameStr(classform->opcname);
|
||||
|
||||
/* Fetch opfamily information */
|
||||
familytup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfamilyoid));
|
||||
if (!HeapTupleIsValid(familytup))
|
||||
elog(ERROR, "cache lookup failed for operator family %u", opfamilyoid);
|
||||
familyform = (Form_pg_opfamily) GETSTRUCT(familytup);
|
||||
|
||||
opfamilyname = NameStr(familyform->opfname);
|
||||
opfamilyname = get_opfamily_name(opfamilyoid, false);
|
||||
|
||||
/* Fetch all operators and support functions of the opfamily */
|
||||
oprlist = SearchSysCacheList1(AMOPSTRATEGY, ObjectIdGetDatum(opfamilyoid));
|
||||
@ -319,7 +311,6 @@ spgvalidate(Oid opclassoid)
|
||||
|
||||
ReleaseCatCacheList(proclist);
|
||||
ReleaseCatCacheList(oprlist);
|
||||
ReleaseSysCache(familytup);
|
||||
ReleaseSysCache(classtup);
|
||||
|
||||
return result;
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include "catalog/pg_inherits.h"
|
||||
#include "catalog/pg_namespace.h"
|
||||
#include "catalog/pg_opclass.h"
|
||||
#include "catalog/pg_opfamily.h"
|
||||
#include "catalog/pg_tablespace.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "commands/comment.h"
|
||||
@ -2147,29 +2146,12 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
|
||||
opfamily = get_opclass_family(opclassOids[attn]);
|
||||
strat = get_op_opfamily_strategy(opid, opfamily);
|
||||
if (strat == 0)
|
||||
{
|
||||
HeapTuple opftuple;
|
||||
Form_pg_opfamily opfform;
|
||||
|
||||
/*
|
||||
* attribute->opclass might not explicitly name the opfamily,
|
||||
* so fetch the name of the selected opfamily for use in the
|
||||
* error message.
|
||||
*/
|
||||
opftuple = SearchSysCache1(OPFAMILYOID,
|
||||
ObjectIdGetDatum(opfamily));
|
||||
if (!HeapTupleIsValid(opftuple))
|
||||
elog(ERROR, "cache lookup failed for opfamily %u",
|
||||
opfamily);
|
||||
opfform = (Form_pg_opfamily) GETSTRUCT(opftuple);
|
||||
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("operator %s is not a member of operator family \"%s\"",
|
||||
format_operator(opid),
|
||||
NameStr(opfform->opfname)),
|
||||
get_opfamily_name(opfamily, false)),
|
||||
errdetail("The exclusion operator must be related to the index operator class for the constraint.")));
|
||||
}
|
||||
|
||||
indexInfo->ii_ExclusionOps[attn] = opid;
|
||||
indexInfo->ii_ExclusionProcs[attn] = get_opcode(opid);
|
||||
@ -2484,21 +2466,13 @@ GetOperatorFromCompareType(Oid opclass, Oid rhstype, CompareType cmptype,
|
||||
}
|
||||
|
||||
if (!OidIsValid(*opid))
|
||||
{
|
||||
HeapTuple tuple;
|
||||
|
||||
tuple = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfamily));
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
elog(ERROR, "cache lookup failed for operator family %u", opfamily);
|
||||
|
||||
ereport(ERROR,
|
||||
errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
cmptype == COMPARE_EQ ? errmsg("could not identify an equality operator for type %s", format_type_be(opcintype)) :
|
||||
cmptype == COMPARE_OVERLAP ? errmsg("could not identify an overlaps operator for type %s", format_type_be(opcintype)) :
|
||||
cmptype == COMPARE_CONTAINED_BY ? errmsg("could not identify a contained-by operator for type %s", format_type_be(opcintype)) : 0,
|
||||
errdetail("There is no suitable operator in operator family \"%s\" for access method \"%s\".",
|
||||
NameStr(((Form_pg_opfamily) GETSTRUCT(tuple))->opfname), "gist"));
|
||||
}
|
||||
get_opfamily_name(opfamily, false), "gist"));
|
||||
}
|
||||
|
||||
/*
|
||||
|
27
src/backend/utils/cache/lsyscache.c
vendored
27
src/backend/utils/cache/lsyscache.c
vendored
@ -30,6 +30,7 @@
|
||||
#include "catalog/pg_language.h"
|
||||
#include "catalog/pg_namespace.h"
|
||||
#include "catalog/pg_opclass.h"
|
||||
#include "catalog/pg_opfamily.h"
|
||||
#include "catalog/pg_operator.h"
|
||||
#include "catalog/pg_proc.h"
|
||||
#include "catalog/pg_publication.h"
|
||||
@ -1273,6 +1274,32 @@ get_opclass_method(Oid opclass)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ---------- OPFAMILY CACHE ---------- */
|
||||
|
||||
char *
|
||||
get_opfamily_name(Oid opfid, bool missing_ok)
|
||||
{
|
||||
HeapTuple tup;
|
||||
char *opfname;
|
||||
Form_pg_opfamily opfform;
|
||||
|
||||
tup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfid));
|
||||
|
||||
if (!HeapTupleIsValid(tup))
|
||||
{
|
||||
if (!missing_ok)
|
||||
elog(ERROR, "cache lookup failed for operator family %u", opfid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
opfform = (Form_pg_opfamily) GETSTRUCT(tup);
|
||||
opfname = pstrdup(NameStr(opfform->opfname));
|
||||
|
||||
ReleaseSysCache(tup);
|
||||
|
||||
return opfname;
|
||||
}
|
||||
|
||||
/* ---------- OPERATOR CACHE ---------- */
|
||||
|
||||
/*
|
||||
|
@ -108,6 +108,7 @@ extern Oid get_opclass_input_type(Oid opclass);
|
||||
extern bool get_opclass_opfamily_and_input_type(Oid opclass,
|
||||
Oid *opfamily, Oid *opcintype);
|
||||
extern Oid get_opclass_method(Oid opclass);
|
||||
extern char *get_opfamily_name(Oid opfid, bool missing_ok);
|
||||
extern RegProcedure get_opcode(Oid opno);
|
||||
extern char *get_opname(Oid opno);
|
||||
extern Oid get_op_rettype(Oid opno);
|
||||
|
Loading…
x
Reference in New Issue
Block a user