mirror of
https://github.com/postgres/postgres.git
synced 2025-07-09 22:41:56 +03:00
Wrap calls to SearchSysCache and related functions using macros.
The purpose of this change is to eliminate the need for every caller of SearchSysCache, SearchSysCacheCopy, SearchSysCacheExists, GetSysCacheOid, and SearchSysCacheList to know the maximum number of allowable keys for a syscache entry (currently 4). This will make it far easier to increase the maximum number of keys in a future release should we choose to do so, and it makes the code shorter, too. Design and review by Tom Lane.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.179 2010/01/02 16:57:49 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.180 2010/02/14 18:42:15 rhaas Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -684,9 +684,7 @@ build_coercion_expression(Node *node,
|
||||
HeapTuple tp;
|
||||
Form_pg_proc procstruct;
|
||||
|
||||
tp = SearchSysCache(PROCOID,
|
||||
ObjectIdGetDatum(funcId),
|
||||
0, 0, 0);
|
||||
tp = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcId));
|
||||
if (!HeapTupleIsValid(tp))
|
||||
elog(ERROR, "cache lookup failed for function %u", funcId);
|
||||
procstruct = (Form_pg_proc) GETSTRUCT(tp);
|
||||
@ -1787,10 +1785,9 @@ IsBinaryCoercible(Oid srctype, Oid targettype)
|
||||
return true;
|
||||
|
||||
/* Else look in pg_cast */
|
||||
tuple = SearchSysCache(CASTSOURCETARGET,
|
||||
ObjectIdGetDatum(srctype),
|
||||
ObjectIdGetDatum(targettype),
|
||||
0, 0);
|
||||
tuple = SearchSysCache2(CASTSOURCETARGET,
|
||||
ObjectIdGetDatum(srctype),
|
||||
ObjectIdGetDatum(targettype));
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
return false; /* no cast */
|
||||
castForm = (Form_pg_cast) GETSTRUCT(tuple);
|
||||
@ -1852,10 +1849,9 @@ find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId,
|
||||
return COERCION_PATH_RELABELTYPE;
|
||||
|
||||
/* Look in pg_cast */
|
||||
tuple = SearchSysCache(CASTSOURCETARGET,
|
||||
ObjectIdGetDatum(sourceTypeId),
|
||||
ObjectIdGetDatum(targetTypeId),
|
||||
0, 0);
|
||||
tuple = SearchSysCache2(CASTSOURCETARGET,
|
||||
ObjectIdGetDatum(sourceTypeId),
|
||||
ObjectIdGetDatum(targetTypeId));
|
||||
|
||||
if (HeapTupleIsValid(tuple))
|
||||
{
|
||||
@ -2017,10 +2013,9 @@ find_typmod_coercion_function(Oid typeId,
|
||||
ReleaseSysCache(targetType);
|
||||
|
||||
/* Look in pg_cast */
|
||||
tuple = SearchSysCache(CASTSOURCETARGET,
|
||||
ObjectIdGetDatum(typeId),
|
||||
ObjectIdGetDatum(typeId),
|
||||
0, 0);
|
||||
tuple = SearchSysCache2(CASTSOURCETARGET,
|
||||
ObjectIdGetDatum(typeId),
|
||||
ObjectIdGetDatum(typeId));
|
||||
|
||||
if (HeapTupleIsValid(tuple))
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.220 2010/01/02 16:57:49 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.221 2010/02/14 18:42:15 rhaas Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1108,9 +1108,8 @@ func_get_detail(List *funcname,
|
||||
}
|
||||
}
|
||||
|
||||
ftup = SearchSysCache(PROCOID,
|
||||
ObjectIdGetDatum(best_candidate->oid),
|
||||
0, 0, 0);
|
||||
ftup = SearchSysCache1(PROCOID,
|
||||
ObjectIdGetDatum(best_candidate->oid));
|
||||
if (!HeapTupleIsValid(ftup)) /* should not happen */
|
||||
elog(ERROR, "cache lookup failed for function %u",
|
||||
best_candidate->oid);
|
||||
@ -1563,9 +1562,7 @@ LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
|
||||
}
|
||||
|
||||
/* Make sure it's an aggregate */
|
||||
ftup = SearchSysCache(PROCOID,
|
||||
ObjectIdGetDatum(oid),
|
||||
0, 0, 0);
|
||||
ftup = SearchSysCache1(PROCOID, ObjectIdGetDatum(oid));
|
||||
if (!HeapTupleIsValid(ftup)) /* should not happen */
|
||||
elog(ERROR, "cache lookup failed for function %u", oid);
|
||||
pform = (Form_pg_proc) GETSTRUCT(ftup);
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_node.c,v 1.107 2010/01/02 16:57:49 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_node.c,v 1.108 2010/02/14 18:42:15 rhaas Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -208,9 +208,7 @@ transformArrayType(Oid arrayType)
|
||||
Form_pg_type type_struct_array;
|
||||
|
||||
/* Get the type tuple for the array */
|
||||
type_tuple_array = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(arrayType),
|
||||
0, 0, 0);
|
||||
type_tuple_array = SearchSysCache1(TYPEOID, ObjectIdGetDatum(arrayType));
|
||||
if (!HeapTupleIsValid(type_tuple_array))
|
||||
elog(ERROR, "cache lookup failed for type %u", arrayType);
|
||||
type_struct_array = (Form_pg_type) GETSTRUCT(type_tuple_array);
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_oper.c,v 1.111 2010/01/02 16:57:50 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_oper.c,v 1.112 2010/02/14 18:42:15 rhaas Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -421,9 +421,7 @@ oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId,
|
||||
operOid = find_oper_cache_entry(&key);
|
||||
if (OidIsValid(operOid))
|
||||
{
|
||||
tup = SearchSysCache(OPEROID,
|
||||
ObjectIdGetDatum(operOid),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operOid));
|
||||
if (HeapTupleIsValid(tup))
|
||||
return (Operator) tup;
|
||||
}
|
||||
@ -463,9 +461,7 @@ oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId,
|
||||
}
|
||||
|
||||
if (OidIsValid(operOid))
|
||||
tup = SearchSysCache(OPEROID,
|
||||
ObjectIdGetDatum(operOid),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operOid));
|
||||
|
||||
if (HeapTupleIsValid(tup))
|
||||
{
|
||||
@ -571,9 +567,7 @@ right_oper(ParseState *pstate, List *op, Oid arg, bool noError, int location)
|
||||
operOid = find_oper_cache_entry(&key);
|
||||
if (OidIsValid(operOid))
|
||||
{
|
||||
tup = SearchSysCache(OPEROID,
|
||||
ObjectIdGetDatum(operOid),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operOid));
|
||||
if (HeapTupleIsValid(tup))
|
||||
return (Operator) tup;
|
||||
}
|
||||
@ -605,9 +599,7 @@ right_oper(ParseState *pstate, List *op, Oid arg, bool noError, int location)
|
||||
}
|
||||
|
||||
if (OidIsValid(operOid))
|
||||
tup = SearchSysCache(OPEROID,
|
||||
ObjectIdGetDatum(operOid),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operOid));
|
||||
|
||||
if (HeapTupleIsValid(tup))
|
||||
{
|
||||
@ -653,9 +645,7 @@ left_oper(ParseState *pstate, List *op, Oid arg, bool noError, int location)
|
||||
operOid = find_oper_cache_entry(&key);
|
||||
if (OidIsValid(operOid))
|
||||
{
|
||||
tup = SearchSysCache(OPEROID,
|
||||
ObjectIdGetDatum(operOid),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operOid));
|
||||
if (HeapTupleIsValid(tup))
|
||||
return (Operator) tup;
|
||||
}
|
||||
@ -699,9 +689,7 @@ left_oper(ParseState *pstate, List *op, Oid arg, bool noError, int location)
|
||||
}
|
||||
|
||||
if (OidIsValid(operOid))
|
||||
tup = SearchSysCache(OPEROID,
|
||||
ObjectIdGetDatum(operOid),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operOid));
|
||||
|
||||
if (HeapTupleIsValid(tup))
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.148 2010/01/02 16:57:50 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.149 2010/02/14 18:42:15 rhaas Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -502,10 +502,9 @@ scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, char *colname,
|
||||
if (attnum != InvalidAttrNumber)
|
||||
{
|
||||
/* now check to see if column actually is defined */
|
||||
if (SearchSysCacheExists(ATTNUM,
|
||||
ObjectIdGetDatum(rte->relid),
|
||||
Int16GetDatum(attnum),
|
||||
0, 0))
|
||||
if (SearchSysCacheExists2(ATTNUM,
|
||||
ObjectIdGetDatum(rte->relid),
|
||||
Int16GetDatum(attnum)))
|
||||
{
|
||||
var = make_var(pstate, rte, attnum, location);
|
||||
/* Require read access to the column */
|
||||
@ -1979,10 +1978,9 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum,
|
||||
HeapTuple tp;
|
||||
Form_pg_attribute att_tup;
|
||||
|
||||
tp = SearchSysCache(ATTNUM,
|
||||
ObjectIdGetDatum(rte->relid),
|
||||
Int16GetDatum(attnum),
|
||||
0, 0);
|
||||
tp = SearchSysCache2(ATTNUM,
|
||||
ObjectIdGetDatum(rte->relid),
|
||||
Int16GetDatum(attnum));
|
||||
if (!HeapTupleIsValid(tp)) /* shouldn't happen */
|
||||
elog(ERROR, "cache lookup failed for attribute %d of relation %u",
|
||||
attnum, rte->relid);
|
||||
@ -2133,10 +2131,9 @@ get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum)
|
||||
HeapTuple tp;
|
||||
Form_pg_attribute att_tup;
|
||||
|
||||
tp = SearchSysCache(ATTNUM,
|
||||
ObjectIdGetDatum(rte->relid),
|
||||
Int16GetDatum(attnum),
|
||||
0, 0);
|
||||
tp = SearchSysCache2(ATTNUM,
|
||||
ObjectIdGetDatum(rte->relid),
|
||||
Int16GetDatum(attnum));
|
||||
if (!HeapTupleIsValid(tp)) /* shouldn't happen */
|
||||
elog(ERROR, "cache lookup failed for attribute %d of relation %u",
|
||||
attnum, rte->relid);
|
||||
@ -2186,10 +2183,9 @@ get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum)
|
||||
HeapTuple tp;
|
||||
Form_pg_attribute att_tup;
|
||||
|
||||
tp = SearchSysCache(ATTNUM,
|
||||
ObjectIdGetDatum(funcrelid),
|
||||
Int16GetDatum(attnum),
|
||||
0, 0);
|
||||
tp = SearchSysCache2(ATTNUM,
|
||||
ObjectIdGetDatum(funcrelid),
|
||||
Int16GetDatum(attnum));
|
||||
if (!HeapTupleIsValid(tp)) /* shouldn't happen */
|
||||
elog(ERROR, "cache lookup failed for attribute %d of relation %u",
|
||||
attnum, funcrelid);
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.105 2010/01/02 16:57:50 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.106 2010/02/14 18:42:15 rhaas Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -143,10 +143,9 @@ LookupTypeName(ParseState *pstate, const TypeName *typeName,
|
||||
Oid namespaceId;
|
||||
|
||||
namespaceId = LookupExplicitNamespace(schemaname);
|
||||
typoid = GetSysCacheOid(TYPENAMENSP,
|
||||
PointerGetDatum(typname),
|
||||
ObjectIdGetDatum(namespaceId),
|
||||
0, 0);
|
||||
typoid = GetSysCacheOid2(TYPENAMENSP,
|
||||
PointerGetDatum(typname),
|
||||
ObjectIdGetDatum(namespaceId));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -166,9 +165,7 @@ LookupTypeName(ParseState *pstate, const TypeName *typeName,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tup = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(typoid),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(typoid));
|
||||
if (!HeapTupleIsValid(tup)) /* should not happen */
|
||||
elog(ERROR, "cache lookup failed for type %u", typoid);
|
||||
|
||||
@ -423,9 +420,7 @@ typeidType(Oid id)
|
||||
{
|
||||
HeapTuple tup;
|
||||
|
||||
tup = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(id),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(id));
|
||||
if (!HeapTupleIsValid(tup))
|
||||
elog(ERROR, "cache lookup failed for type %u", id);
|
||||
return (Type) tup;
|
||||
@ -532,9 +527,7 @@ typeidTypeRelid(Oid type_id)
|
||||
Form_pg_type type;
|
||||
Oid result;
|
||||
|
||||
typeTuple = SearchSysCache(TYPEOID,
|
||||
ObjectIdGetDatum(type_id),
|
||||
0, 0, 0);
|
||||
typeTuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type_id));
|
||||
if (!HeapTupleIsValid(typeTuple))
|
||||
elog(ERROR, "cache lookup failed for type %u", type_id);
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.38 2010/02/03 05:46:37 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.39 2010/02/14 18:42:15 rhaas Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -889,9 +889,7 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
|
||||
* Fetch pg_class tuple of source index. We can't use the copy in the
|
||||
* relcache entry because it doesn't include optional fields.
|
||||
*/
|
||||
ht_idxrel = SearchSysCache(RELOID,
|
||||
ObjectIdGetDatum(source_relid),
|
||||
0, 0, 0);
|
||||
ht_idxrel = SearchSysCache1(RELOID, ObjectIdGetDatum(source_relid));
|
||||
if (!HeapTupleIsValid(ht_idxrel))
|
||||
elog(ERROR, "cache lookup failed for relation %u", source_relid);
|
||||
idxrelrec = (Form_pg_class) GETSTRUCT(ht_idxrel);
|
||||
@ -943,9 +941,8 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
|
||||
HeapTuple ht_constr;
|
||||
Form_pg_constraint conrec;
|
||||
|
||||
ht_constr = SearchSysCache(CONSTROID,
|
||||
ObjectIdGetDatum(constraintId),
|
||||
0, 0, 0);
|
||||
ht_constr = SearchSysCache1(CONSTROID,
|
||||
ObjectIdGetDatum(constraintId));
|
||||
if (!HeapTupleIsValid(ht_constr))
|
||||
elog(ERROR, "cache lookup failed for constraint %u",
|
||||
constraintId);
|
||||
@ -984,9 +981,8 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
|
||||
char *nspname;
|
||||
List *namelist;
|
||||
|
||||
opertup = SearchSysCache(OPEROID,
|
||||
ObjectIdGetDatum(operid),
|
||||
0, 0, 0);
|
||||
opertup = SearchSysCache1(OPEROID,
|
||||
ObjectIdGetDatum(operid));
|
||||
if (!HeapTupleIsValid(opertup))
|
||||
elog(ERROR, "cache lookup failed for operator %u",
|
||||
operid);
|
||||
@ -1138,9 +1134,7 @@ get_opclass(Oid opclass, Oid actual_datatype)
|
||||
Form_pg_opclass opc_rec;
|
||||
List *result = NIL;
|
||||
|
||||
ht_opc = SearchSysCache(CLAOID,
|
||||
ObjectIdGetDatum(opclass),
|
||||
0, 0, 0);
|
||||
ht_opc = SearchSysCache1(CLAOID, ObjectIdGetDatum(opclass));
|
||||
if (!HeapTupleIsValid(ht_opc))
|
||||
elog(ERROR, "cache lookup failed for opclass %u", opclass);
|
||||
opc_rec = (Form_pg_opclass) GETSTRUCT(ht_opc);
|
||||
|
Reference in New Issue
Block a user