mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +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:
@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tsearchcmds.c,v 1.19 2010/01/02 16:57:39 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tsearchcmds.c,v 1.20 2010/02/14 18:42:14 rhaas Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -338,9 +338,7 @@ RemoveTSParserById(Oid prsId)
|
||||
|
||||
relation = heap_open(TSParserRelationId, RowExclusiveLock);
|
||||
|
||||
tup = SearchSysCache(TSPARSEROID,
|
||||
ObjectIdGetDatum(prsId),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(TSPARSEROID, ObjectIdGetDatum(prsId));
|
||||
|
||||
if (!HeapTupleIsValid(tup))
|
||||
elog(ERROR, "cache lookup failed for text search parser %u", prsId);
|
||||
@ -372,19 +370,16 @@ RenameTSParser(List *oldname, const char *newname)
|
||||
|
||||
prsId = TSParserGetPrsid(oldname, false);
|
||||
|
||||
tup = SearchSysCacheCopy(TSPARSEROID,
|
||||
ObjectIdGetDatum(prsId),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCacheCopy1(TSPARSEROID, ObjectIdGetDatum(prsId));
|
||||
|
||||
if (!HeapTupleIsValid(tup)) /* should not happen */
|
||||
elog(ERROR, "cache lookup failed for text search parser %u", prsId);
|
||||
|
||||
namespaceOid = ((Form_pg_ts_parser) GETSTRUCT(tup))->prsnamespace;
|
||||
|
||||
if (SearchSysCacheExists(TSPARSERNAMENSP,
|
||||
PointerGetDatum(newname),
|
||||
ObjectIdGetDatum(namespaceOid),
|
||||
0, 0))
|
||||
if (SearchSysCacheExists2(TSPARSERNAMENSP,
|
||||
PointerGetDatum(newname),
|
||||
ObjectIdGetDatum(namespaceOid)))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_OBJECT),
|
||||
errmsg("text search parser \"%s\" already exists",
|
||||
@ -450,9 +445,7 @@ verify_dictoptions(Oid tmplId, List *dictoptions)
|
||||
if (!IsUnderPostmaster)
|
||||
return;
|
||||
|
||||
tup = SearchSysCache(TSTEMPLATEOID,
|
||||
ObjectIdGetDatum(tmplId),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(TSTEMPLATEOID, ObjectIdGetDatum(tmplId));
|
||||
if (!HeapTupleIsValid(tup)) /* should not happen */
|
||||
elog(ERROR, "cache lookup failed for text search template %u",
|
||||
tmplId);
|
||||
@ -591,9 +584,7 @@ RenameTSDictionary(List *oldname, const char *newname)
|
||||
|
||||
dictId = TSDictionaryGetDictid(oldname, false);
|
||||
|
||||
tup = SearchSysCacheCopy(TSDICTOID,
|
||||
ObjectIdGetDatum(dictId),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCacheCopy1(TSDICTOID, ObjectIdGetDatum(dictId));
|
||||
|
||||
if (!HeapTupleIsValid(tup)) /* should not happen */
|
||||
elog(ERROR, "cache lookup failed for text search dictionary %u",
|
||||
@ -601,10 +592,9 @@ RenameTSDictionary(List *oldname, const char *newname)
|
||||
|
||||
namespaceOid = ((Form_pg_ts_dict) GETSTRUCT(tup))->dictnamespace;
|
||||
|
||||
if (SearchSysCacheExists(TSDICTNAMENSP,
|
||||
PointerGetDatum(newname),
|
||||
ObjectIdGetDatum(namespaceOid),
|
||||
0, 0))
|
||||
if (SearchSysCacheExists2(TSDICTNAMENSP,
|
||||
PointerGetDatum(newname),
|
||||
ObjectIdGetDatum(namespaceOid)))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_OBJECT),
|
||||
errmsg("text search dictionary \"%s\" already exists",
|
||||
@ -673,9 +663,7 @@ RemoveTSDictionaries(DropStmt *drop)
|
||||
continue;
|
||||
}
|
||||
|
||||
tup = SearchSysCache(TSDICTOID,
|
||||
ObjectIdGetDatum(dictOid),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(TSDICTOID, ObjectIdGetDatum(dictOid));
|
||||
if (!HeapTupleIsValid(tup)) /* should not happen */
|
||||
elog(ERROR, "cache lookup failed for text search dictionary %u",
|
||||
dictOid);
|
||||
@ -712,9 +700,7 @@ RemoveTSDictionaryById(Oid dictId)
|
||||
|
||||
relation = heap_open(TSDictionaryRelationId, RowExclusiveLock);
|
||||
|
||||
tup = SearchSysCache(TSDICTOID,
|
||||
ObjectIdGetDatum(dictId),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(TSDICTOID, ObjectIdGetDatum(dictId));
|
||||
|
||||
if (!HeapTupleIsValid(tup))
|
||||
elog(ERROR, "cache lookup failed for text search dictionary %u",
|
||||
@ -749,9 +735,7 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt)
|
||||
|
||||
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
|
||||
|
||||
tup = SearchSysCache(TSDICTOID,
|
||||
ObjectIdGetDatum(dictId),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(TSDICTOID, ObjectIdGetDatum(dictId));
|
||||
|
||||
if (!HeapTupleIsValid(tup))
|
||||
elog(ERROR, "cache lookup failed for text search dictionary %u",
|
||||
@ -859,9 +843,7 @@ AlterTSDictionaryOwner(List *name, Oid newOwnerId)
|
||||
|
||||
dictId = TSDictionaryGetDictid(name, false);
|
||||
|
||||
tup = SearchSysCacheCopy(TSDICTOID,
|
||||
ObjectIdGetDatum(dictId),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCacheCopy1(TSDICTOID, ObjectIdGetDatum(dictId));
|
||||
|
||||
if (!HeapTupleIsValid(tup)) /* should not happen */
|
||||
elog(ERROR, "cache lookup failed for text search dictionary %u",
|
||||
@ -1093,9 +1075,7 @@ RenameTSTemplate(List *oldname, const char *newname)
|
||||
|
||||
tmplId = TSTemplateGetTmplid(oldname, false);
|
||||
|
||||
tup = SearchSysCacheCopy(TSTEMPLATEOID,
|
||||
ObjectIdGetDatum(tmplId),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCacheCopy1(TSTEMPLATEOID, ObjectIdGetDatum(tmplId));
|
||||
|
||||
if (!HeapTupleIsValid(tup)) /* should not happen */
|
||||
elog(ERROR, "cache lookup failed for text search template %u",
|
||||
@ -1103,10 +1083,9 @@ RenameTSTemplate(List *oldname, const char *newname)
|
||||
|
||||
namespaceOid = ((Form_pg_ts_template) GETSTRUCT(tup))->tmplnamespace;
|
||||
|
||||
if (SearchSysCacheExists(TSTEMPLATENAMENSP,
|
||||
PointerGetDatum(newname),
|
||||
ObjectIdGetDatum(namespaceOid),
|
||||
0, 0))
|
||||
if (SearchSysCacheExists2(TSTEMPLATENAMENSP,
|
||||
PointerGetDatum(newname),
|
||||
ObjectIdGetDatum(namespaceOid)))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_OBJECT),
|
||||
errmsg("text search template \"%s\" already exists",
|
||||
@ -1190,9 +1169,7 @@ RemoveTSTemplateById(Oid tmplId)
|
||||
|
||||
relation = heap_open(TSTemplateRelationId, RowExclusiveLock);
|
||||
|
||||
tup = SearchSysCache(TSTEMPLATEOID,
|
||||
ObjectIdGetDatum(tmplId),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(TSTEMPLATEOID, ObjectIdGetDatum(tmplId));
|
||||
|
||||
if (!HeapTupleIsValid(tup))
|
||||
elog(ERROR, "cache lookup failed for text search template %u",
|
||||
@ -1221,9 +1198,7 @@ GetTSConfigTuple(List *names)
|
||||
if (!OidIsValid(cfgId))
|
||||
return NULL;
|
||||
|
||||
tup = SearchSysCache(TSCONFIGOID,
|
||||
ObjectIdGetDatum(cfgId),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(TSCONFIGOID, ObjectIdGetDatum(cfgId));
|
||||
|
||||
if (!HeapTupleIsValid(tup)) /* should not happen */
|
||||
elog(ERROR, "cache lookup failed for text search configuration %u",
|
||||
@ -1376,9 +1351,7 @@ DefineTSConfiguration(List *names, List *parameters)
|
||||
{
|
||||
Form_pg_ts_config cfg;
|
||||
|
||||
tup = SearchSysCache(TSCONFIGOID,
|
||||
ObjectIdGetDatum(sourceOid),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(TSCONFIGOID, ObjectIdGetDatum(sourceOid));
|
||||
if (!HeapTupleIsValid(tup))
|
||||
elog(ERROR, "cache lookup failed for text search configuration %u",
|
||||
sourceOid);
|
||||
@ -1490,9 +1463,7 @@ RenameTSConfiguration(List *oldname, const char *newname)
|
||||
|
||||
cfgId = TSConfigGetCfgid(oldname, false);
|
||||
|
||||
tup = SearchSysCacheCopy(TSCONFIGOID,
|
||||
ObjectIdGetDatum(cfgId),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCacheCopy1(TSCONFIGOID, ObjectIdGetDatum(cfgId));
|
||||
|
||||
if (!HeapTupleIsValid(tup)) /* should not happen */
|
||||
elog(ERROR, "cache lookup failed for text search configuration %u",
|
||||
@ -1500,10 +1471,9 @@ RenameTSConfiguration(List *oldname, const char *newname)
|
||||
|
||||
namespaceOid = ((Form_pg_ts_config) GETSTRUCT(tup))->cfgnamespace;
|
||||
|
||||
if (SearchSysCacheExists(TSCONFIGNAMENSP,
|
||||
PointerGetDatum(newname),
|
||||
ObjectIdGetDatum(namespaceOid),
|
||||
0, 0))
|
||||
if (SearchSysCacheExists2(TSCONFIGNAMENSP,
|
||||
PointerGetDatum(newname),
|
||||
ObjectIdGetDatum(namespaceOid)))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DUPLICATE_OBJECT),
|
||||
errmsg("text search configuration \"%s\" already exists",
|
||||
@ -1608,9 +1578,7 @@ RemoveTSConfigurationById(Oid cfgId)
|
||||
/* Remove the pg_ts_config entry */
|
||||
relCfg = heap_open(TSConfigRelationId, RowExclusiveLock);
|
||||
|
||||
tup = SearchSysCache(TSCONFIGOID,
|
||||
ObjectIdGetDatum(cfgId),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCache1(TSCONFIGOID, ObjectIdGetDatum(cfgId));
|
||||
|
||||
if (!HeapTupleIsValid(tup))
|
||||
elog(ERROR, "cache lookup failed for text search dictionary %u",
|
||||
@ -1660,9 +1628,7 @@ AlterTSConfigurationOwner(List *name, Oid newOwnerId)
|
||||
|
||||
cfgId = TSConfigGetCfgid(name, false);
|
||||
|
||||
tup = SearchSysCacheCopy(TSCONFIGOID,
|
||||
ObjectIdGetDatum(cfgId),
|
||||
0, 0, 0);
|
||||
tup = SearchSysCacheCopy1(TSCONFIGOID, ObjectIdGetDatum(cfgId));
|
||||
|
||||
if (!HeapTupleIsValid(tup)) /* should not happen */
|
||||
elog(ERROR, "cache lookup failed for text search configuration %u",
|
||||
|
Reference in New Issue
Block a user