mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
Change SearchSysCache coding conventions so that a reference count is
maintained for each cache entry. A cache entry will not be freed until the matching ReleaseSysCache call has been executed. This eliminates worries about cache entries getting dropped while still in use. See my posting to pg-hackers of even date for more info.
This commit is contained in:
@ -48,7 +48,6 @@ void
|
||||
CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
{
|
||||
char languageName[NAMEDATALEN];
|
||||
HeapTuple langTup;
|
||||
HeapTuple procTup;
|
||||
|
||||
Oid typev[FUNC_MAX_ARGS];
|
||||
@ -77,10 +76,9 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
*/
|
||||
case_translate_language_name(stmt->plname, languageName);
|
||||
|
||||
langTup = SearchSysCacheTuple(LANGNAME,
|
||||
PointerGetDatum(languageName),
|
||||
0, 0, 0);
|
||||
if (HeapTupleIsValid(langTup))
|
||||
if (SearchSysCacheExists(LANGNAME,
|
||||
PointerGetDatum(languageName),
|
||||
0, 0, 0))
|
||||
elog(ERROR, "Language %s already exists", languageName);
|
||||
|
||||
/* ----------------
|
||||
@ -89,21 +87,17 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
* ----------------
|
||||
*/
|
||||
memset(typev, 0, sizeof(typev));
|
||||
procTup = SearchSysCacheTuple(PROCNAME,
|
||||
PointerGetDatum(stmt->plhandler),
|
||||
Int32GetDatum(0),
|
||||
PointerGetDatum(typev),
|
||||
0);
|
||||
procTup = SearchSysCache(PROCNAME,
|
||||
PointerGetDatum(stmt->plhandler),
|
||||
Int32GetDatum(0),
|
||||
PointerGetDatum(typev),
|
||||
0);
|
||||
if (!HeapTupleIsValid(procTup))
|
||||
{
|
||||
elog(ERROR, "PL handler function %s() doesn't exist",
|
||||
stmt->plhandler);
|
||||
}
|
||||
if (((Form_pg_proc) GETSTRUCT(procTup))->prorettype != InvalidOid)
|
||||
{
|
||||
elog(ERROR, "PL handler function %s() isn't of return type Opaque",
|
||||
stmt->plhandler);
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* Insert the new language into pg_language
|
||||
@ -123,6 +117,8 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
|
||||
values[i++] = DirectFunctionCall1(textin,
|
||||
CStringGetDatum(stmt->plcompiler));
|
||||
|
||||
ReleaseSysCache(procTup);
|
||||
|
||||
rel = heap_openr(LanguageRelationName, RowExclusiveLock);
|
||||
|
||||
tupDesc = rel->rd_att;
|
||||
@ -173,9 +169,9 @@ DropProceduralLanguage(DropPLangStmt *stmt)
|
||||
|
||||
rel = heap_openr(LanguageRelationName, RowExclusiveLock);
|
||||
|
||||
langTup = SearchSysCacheTupleCopy(LANGNAME,
|
||||
PointerGetDatum(languageName),
|
||||
0, 0, 0);
|
||||
langTup = SearchSysCacheCopy(LANGNAME,
|
||||
PointerGetDatum(languageName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(langTup))
|
||||
elog(ERROR, "Language %s doesn't exist", languageName);
|
||||
|
||||
|
Reference in New Issue
Block a user