diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-11-16 22:30:52 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-11-16 22:30:52 +0000 |
commit | a933ee38bbb8dffbc48a3363a94ff6f2a9f7964d (patch) | |
tree | 1c32737389b2530e7152dc2287161b36d9001e8c /src/backend/utils/adt | |
parent | cff23842a4c68301ddf34559c7af383bb5557054 (diff) | |
download | postgresql-a933ee38bbb8dffbc48a3363a94ff6f2a9f7964d.tar.gz postgresql-a933ee38bbb8dffbc48a3363a94ff6f2a9f7964d.zip |
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.
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r-- | src/backend/utils/adt/acl.c | 18 | ||||
-rw-r--r-- | src/backend/utils/adt/arrayfuncs.c | 9 | ||||
-rw-r--r-- | src/backend/utils/adt/format_type.c | 18 | ||||
-rw-r--r-- | src/backend/utils/adt/regproc.c | 20 | ||||
-rw-r--r-- | src/backend/utils/adt/ri_triggers.c | 18 | ||||
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 98 | ||||
-rw-r--r-- | src/backend/utils/adt/selfuncs.c | 56 | ||||
-rw-r--r-- | src/backend/utils/adt/sets.c | 40 |
8 files changed, 158 insertions, 119 deletions
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index 1a2b2ef953e..a8bc5e349a3 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.52 2000/11/03 19:01:36 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.53 2000/11/16 22:30:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -174,12 +174,13 @@ aclparse(char *s, AclItem *aip, unsigned *modechg) switch (aip->ai_idtype) { case ACL_IDTYPE_UID: - htup = SearchSysCacheTuple(SHADOWNAME, - PointerGetDatum(name), - 0, 0, 0); + htup = SearchSysCache(SHADOWNAME, + PointerGetDatum(name), + 0, 0, 0); if (!HeapTupleIsValid(htup)) elog(ERROR, "aclparse: non-existent user \"%s\"", name); aip->ai_id = ((Form_pg_shadow) GETSTRUCT(htup))->usesysid; + ReleaseSysCache(htup); break; case ACL_IDTYPE_GID: aip->ai_id = get_grosysid(name); @@ -272,9 +273,9 @@ aclitemout(PG_FUNCTION_ARGS) switch (aip->ai_idtype) { case ACL_IDTYPE_UID: - htup = SearchSysCacheTuple(SHADOWSYSID, - ObjectIdGetDatum(aip->ai_id), - 0, 0, 0); + htup = SearchSysCache(SHADOWSYSID, + ObjectIdGetDatum(aip->ai_id), + 0, 0, 0); if (!HeapTupleIsValid(htup)) { /* Generate numeric UID if we don't find an entry */ @@ -286,9 +287,12 @@ aclitemout(PG_FUNCTION_ARGS) pfree(tmp); } else + { strncat(p, (char *) &((Form_pg_shadow) GETSTRUCT(htup))->usename, sizeof(NameData)); + ReleaseSysCache(htup); + } break; case ACL_IDTYPE_GID: strcat(p, "group "); diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index 44f58840c36..47c1b814c4d 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.65 2000/11/14 23:28:13 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.66 2000/11/16 22:30:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1590,9 +1590,9 @@ system_cache_lookup(Oid element_type, HeapTuple typeTuple; Form_pg_type typeStruct; - typeTuple = SearchSysCacheTuple(TYPEOID, - ObjectIdGetDatum(element_type), - 0, 0, 0); + typeTuple = SearchSysCache(TYPEOID, + ObjectIdGetDatum(element_type), + 0, 0, 0); if (!HeapTupleIsValid(typeTuple)) elog(ERROR, "array_out: Cache lookup failed for type %u", element_type); @@ -1607,6 +1607,7 @@ system_cache_lookup(Oid element_type, *proc = typeStruct->typinput; else *proc = typeStruct->typoutput; + ReleaseSysCache(typeTuple); } /* diff --git a/src/backend/utils/adt/format_type.c b/src/backend/utils/adt/format_type.c index f32122173d8..6022dc78519 100644 --- a/src/backend/utils/adt/format_type.c +++ b/src/backend/utils/adt/format_type.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.5 2000/08/26 21:53:41 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.6 2000/11/16 22:30:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -98,9 +98,9 @@ format_type_internal(Oid type_oid, int32 typemod) if (type_oid == InvalidOid) return pstrdup("-"); - tuple = SearchSysCacheTuple(TYPEOID, ObjectIdGetDatum(type_oid), - 0, 0, 0); - + tuple = SearchSysCache(TYPEOID, + ObjectIdGetDatum(type_oid), + 0, 0, 0); if (!HeapTupleIsValid(tuple)) return pstrdup("???"); @@ -108,9 +108,11 @@ format_type_internal(Oid type_oid, int32 typemod) typlen = ((Form_pg_type) GETSTRUCT(tuple))->typlen; if (array_base_type != 0 && typlen < 0) { - tuple = SearchSysCacheTuple(TYPEOID, - ObjectIdGetDatum(array_base_type), - 0, 0, 0); + /* Switch our attention to the array element type */ + ReleaseSysCache(tuple); + tuple = SearchSysCache(TYPEOID, + ObjectIdGetDatum(array_base_type), + 0, 0, 0); if (!HeapTupleIsValid(tuple)) return pstrdup("???[]"); is_array = true; @@ -211,6 +213,8 @@ format_type_internal(Oid type_oid, int32 typemod) if (is_array) buf = psnprintf(strlen(buf) + 3, "%s[]", buf); + ReleaseSysCache(tuple); + return buf; } diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c index 84c4694115d..4a2bb3c4fd6 100644 --- a/src/backend/utils/adt/regproc.c +++ b/src/backend/utils/adt/regproc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.58 2000/07/09 21:30:12 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.59 2000/11/16 22:30:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -55,13 +55,12 @@ regprocin(PG_FUNCTION_ARGS) if (pro_name_or_oid[0] >= '0' && pro_name_or_oid[0] <= '9') { - proctup = SearchSysCacheTuple(PROCOID, - DirectFunctionCall1(oidin, + result = (RegProcedure) + GetSysCacheOid(PROCOID, + DirectFunctionCall1(oidin, CStringGetDatum(pro_name_or_oid)), - 0, 0, 0); - if (HeapTupleIsValid(proctup)) - result = (RegProcedure) proctup->t_data->t_oid; - else + 0, 0, 0); + if (!RegProcedureIsValid(result)) elog(ERROR, "No procedure with oid %s", pro_name_or_oid); } else @@ -176,9 +175,9 @@ regprocout(PG_FUNCTION_ARGS) if (!IsBootstrapProcessingMode()) { - proctup = SearchSysCacheTuple(PROCOID, - ObjectIdGetDatum(proid), - 0, 0, 0); + proctup = SearchSysCache(PROCOID, + ObjectIdGetDatum(proid), + 0, 0, 0); if (HeapTupleIsValid(proctup)) { @@ -186,6 +185,7 @@ regprocout(PG_FUNCTION_ARGS) s = NameStr(((Form_pg_proc) GETSTRUCT(proctup))->proname); StrNCpy(result, s, NAMEDATALEN); + ReleaseSysCache(proctup); } else { diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c index 723adcda35c..5bfea0ff42f 100644 --- a/src/backend/utils/adt/ri_triggers.c +++ b/src/backend/utils/adt/ri_triggers.c @@ -6,7 +6,7 @@ * * 1999 Jan Wieck * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.17 2000/09/25 22:34:20 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.18 2000/11/16 22:30:31 tgl Exp $ * * ---------- */ @@ -3300,24 +3300,26 @@ ri_AttributesEqual(Oid typeid, Datum oldvalue, Datum newvalue) HeapTuple opr_tup; Form_pg_operator opr_struct; - opr_tup = SearchSysCacheTuple(OPERNAME, - PointerGetDatum("="), - ObjectIdGetDatum(typeid), - ObjectIdGetDatum(typeid), - CharGetDatum('b')); - + opr_tup = SearchSysCache(OPERNAME, + PointerGetDatum("="), + ObjectIdGetDatum(typeid), + ObjectIdGetDatum(typeid), + CharGetDatum('b')); if (!HeapTupleIsValid(opr_tup)) elog(ERROR, "ri_AttributesEqual(): cannot find '=' operator " "for type %u", typeid); opr_struct = (Form_pg_operator) GETSTRUCT(opr_tup); entry = (RI_OpreqHashEntry *) hash_search(ri_opreq_cache, - (char *) &typeid, HASH_ENTER, &found); + (char *) &typeid, + HASH_ENTER, + &found); if (entry == NULL) elog(FATAL, "can't insert into RI operator cache"); entry->typeid = typeid; fmgr_info(opr_struct->oprcode, &(entry->oprfmgrinfo)); + ReleaseSysCache(opr_tup); } /* ---------- diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index cc25a5a026a..3cd543b5e68 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * back to source text * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.68 2000/11/05 00:15:53 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.69 2000/11/16 22:30:31 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -374,8 +374,9 @@ pg_get_indexdef(PG_FUNCTION_ARGS) * Fetch the pg_index tuple by the Oid of the index * ---------- */ - ht_idx = SearchSysCacheTuple(INDEXRELID, - ObjectIdGetDatum(indexrelid), 0, 0, 0); + ht_idx = SearchSysCache(INDEXRELID, + ObjectIdGetDatum(indexrelid), + 0, 0, 0); if (!HeapTupleIsValid(ht_idx)) elog(ERROR, "syscache lookup for index %u failed", indexrelid); idxrec = (Form_pg_index) GETSTRUCT(ht_idx); @@ -384,8 +385,9 @@ pg_get_indexdef(PG_FUNCTION_ARGS) * Fetch the pg_class tuple of the index relation * ---------- */ - ht_idxrel = SearchSysCacheTuple(RELOID, - ObjectIdGetDatum(idxrec->indexrelid), 0, 0, 0); + ht_idxrel = SearchSysCache(RELOID, + ObjectIdGetDatum(idxrec->indexrelid), + 0, 0, 0); if (!HeapTupleIsValid(ht_idxrel)) elog(ERROR, "syscache lookup for relid %u failed", idxrec->indexrelid); idxrelrec = (Form_pg_class) GETSTRUCT(ht_idxrel); @@ -394,8 +396,9 @@ pg_get_indexdef(PG_FUNCTION_ARGS) * Fetch the pg_class tuple of the indexed relation * ---------- */ - ht_indrel = SearchSysCacheTuple(RELOID, - ObjectIdGetDatum(idxrec->indrelid), 0, 0, 0); + ht_indrel = SearchSysCache(RELOID, + ObjectIdGetDatum(idxrec->indrelid), + 0, 0, 0); if (!HeapTupleIsValid(ht_indrel)) elog(ERROR, "syscache lookup for relid %u failed", idxrec->indrelid); indrelrec = (Form_pg_class) GETSTRUCT(ht_indrel); @@ -484,12 +487,13 @@ pg_get_indexdef(PG_FUNCTION_ARGS) HeapTuple proctup; Form_pg_proc procStruct; - proctup = SearchSysCacheTuple(PROCOID, - ObjectIdGetDatum(idxrec->indproc), 0, 0, 0); + proctup = SearchSysCache(PROCOID, + ObjectIdGetDatum(idxrec->indproc), + 0, 0, 0); if (!HeapTupleIsValid(proctup)) elog(ERROR, "cache lookup for proc %u failed", idxrec->indproc); - procStruct = (Form_pg_proc) GETSTRUCT(proctup); + appendStringInfo(&buf, "%s(%s) ", quote_identifier(pstrdup(NameStr(procStruct->proname))), keybuf.data); @@ -508,6 +512,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS) appendStringInfo(&buf, "%s", quote_identifier(SPI_getvalue(spi_tup, spi_ttc, spi_fno))); + ReleaseSysCache(proctup); } else /* ---------- @@ -523,15 +528,19 @@ pg_get_indexdef(PG_FUNCTION_ARGS) appendStringInfo(&buf, ")"); /* ---------- - * Create the result in upper executor memory + * Create the result in upper executor memory, and free objects * ---------- */ len = buf.len + VARHDRSZ; indexdef = SPI_palloc(len); VARATT_SIZEP(indexdef) = len; memcpy(VARDATA(indexdef), buf.data, buf.len); + pfree(buf.data); pfree(keybuf.data); + ReleaseSysCache(ht_idx); + ReleaseSysCache(ht_idxrel); + ReleaseSysCache(ht_indrel); /* ---------- * Disconnect from SPI manager @@ -568,13 +577,14 @@ pg_get_userbyid(PG_FUNCTION_ARGS) * Get the pg_shadow entry and print the result * ---------- */ - usertup = SearchSysCacheTuple(SHADOWSYSID, - ObjectIdGetDatum(uid), - 0, 0, 0); + usertup = SearchSysCache(SHADOWSYSID, + ObjectIdGetDatum(uid), + 0, 0, 0); if (HeapTupleIsValid(usertup)) { user_rec = (Form_pg_shadow) GETSTRUCT(usertup); StrNCpy(NameStr(*result), NameStr(user_rec->usename), NAMEDATALEN); + ReleaseSysCache(usertup); } else sprintf(NameStr(*result), "unknown (UID=%d)", uid); @@ -1392,10 +1402,11 @@ get_rule_expr(Node *node, deparse_context *context) HeapTuple tp; Form_pg_operator optup; - tp = SearchSysCacheTuple(OPEROID, - ObjectIdGetDatum(opno), - 0, 0, 0); - Assert(HeapTupleIsValid(tp)); + tp = SearchSysCache(OPEROID, + ObjectIdGetDatum(opno), + 0, 0, 0); + if (!HeapTupleIsValid(tp)) + elog(ERROR, "cache lookup for operator %u failed", opno); optup = (Form_pg_operator) GETSTRUCT(tp); switch (optup->oprkind) { @@ -1414,6 +1425,7 @@ get_rule_expr(Node *node, deparse_context *context) default: elog(ERROR, "get_rule_expr: bogus oprkind"); } + ReleaseSysCache(tp); } appendStringInfoChar(buf, ')'); break; @@ -1524,9 +1536,9 @@ get_rule_expr(Node *node, deparse_context *context) /* we do NOT parenthesize the arg expression, for now */ get_rule_expr(fselect->arg, context); - typetup = SearchSysCacheTuple(TYPEOID, - ObjectIdGetDatum(exprType(fselect->arg)), - 0, 0, 0); + typetup = SearchSysCache(TYPEOID, + ObjectIdGetDatum(exprType(fselect->arg)), + 0, 0, 0); if (!HeapTupleIsValid(typetup)) elog(ERROR, "cache lookup of type %u failed", exprType(fselect->arg)); @@ -1538,6 +1550,7 @@ get_rule_expr(Node *node, deparse_context *context) fieldname = get_relid_attribute_name(typrelid, fselect->fieldnum); appendStringInfo(buf, ".%s", quote_identifier(fieldname)); + ReleaseSysCache(typetup); } break; @@ -1550,9 +1563,9 @@ get_rule_expr(Node *node, deparse_context *context) appendStringInfoChar(buf, '('); get_rule_expr(relabel->arg, context); - typetup = SearchSysCacheTuple(TYPEOID, + typetup = SearchSysCache(TYPEOID, ObjectIdGetDatum(relabel->resulttype), - 0, 0, 0); + 0, 0, 0); if (!HeapTupleIsValid(typetup)) elog(ERROR, "cache lookup of type %u failed", relabel->resulttype); @@ -1560,6 +1573,7 @@ get_rule_expr(Node *node, deparse_context *context) extval = pstrdup(NameStr(typeStruct->typname)); appendStringInfo(buf, ")::%s", quote_identifier(extval)); pfree(extval); + ReleaseSysCache(typetup); } break; @@ -1616,14 +1630,14 @@ get_func_expr(Expr *expr, deparse_context *context) /* * Get the functions pg_proc tuple */ - proctup = SearchSysCacheTuple(PROCOID, - ObjectIdGetDatum(func->funcid), - 0, 0, 0); + proctup = SearchSysCache(PROCOID, + ObjectIdGetDatum(func->funcid), + 0, 0, 0); if (!HeapTupleIsValid(proctup)) elog(ERROR, "cache lookup for proc %u failed", func->funcid); procStruct = (Form_pg_proc) GETSTRUCT(proctup); - proname = pstrdup(NameStr(procStruct->proname)); + proname = NameStr(procStruct->proname); /* * nullvalue() and nonnullvalue() should get turned into special @@ -1636,6 +1650,7 @@ get_func_expr(Expr *expr, deparse_context *context) appendStringInfoChar(buf, '('); get_rule_expr((Node *) lfirst(expr->args), context); appendStringInfo(buf, " ISNULL)"); + ReleaseSysCache(proctup); return; } if (strcmp(proname, "nonnullvalue") == 0) @@ -1643,6 +1658,7 @@ get_func_expr(Expr *expr, deparse_context *context) appendStringInfoChar(buf, '('); get_rule_expr((Node *) lfirst(expr->args), context); appendStringInfo(buf, " NOTNULL)"); + ReleaseSysCache(proctup); return; } } @@ -1657,8 +1673,9 @@ get_func_expr(Expr *expr, deparse_context *context) /* * Strip off any RelabelType on the input, so we don't print - * redundancies like x::bpchar::char(8). XXX Are there any cases - * where this is a bad idea? + * redundancies like x::bpchar::char(8). + * + * XXX Are there any cases where this is a bad idea? */ if (IsA(arg, RelabelType)) arg = ((RelabelType *) arg)->arg; @@ -1696,6 +1713,8 @@ get_func_expr(Expr *expr, deparse_context *context) } else appendStringInfo(buf, "%s", quote_identifier(proname)); + + ReleaseSysCache(proctup); return; } @@ -1711,6 +1730,8 @@ get_func_expr(Expr *expr, deparse_context *context) get_rule_expr((Node *) lfirst(l), context); } appendStringInfoChar(buf, ')'); + + ReleaseSysCache(proctup); } @@ -1766,9 +1787,9 @@ get_const_expr(Const *constval, deparse_context *context) char *extval; char *valptr; - typetup = SearchSysCacheTuple(TYPEOID, - ObjectIdGetDatum(constval->consttype), - 0, 0, 0); + typetup = SearchSysCache(TYPEOID, + ObjectIdGetDatum(constval->consttype), + 0, 0, 0); if (!HeapTupleIsValid(typetup)) elog(ERROR, "cache lookup of type %u failed", constval->consttype); @@ -1785,6 +1806,7 @@ get_const_expr(Const *constval, deparse_context *context) extval = pstrdup(NameStr(typeStruct->typname)); appendStringInfo(buf, "NULL::%s", quote_identifier(extval)); pfree(extval); + ReleaseSysCache(typetup); return; } @@ -1843,6 +1865,8 @@ get_const_expr(Const *constval, deparse_context *context) pfree(extval); break; } + + ReleaseSysCache(typetup); } @@ -2198,14 +2222,18 @@ get_relation_name(Oid relid) { HeapTuple classtup; Form_pg_class classStruct; + char *result; - classtup = SearchSysCacheTuple(RELOID, - ObjectIdGetDatum(relid), 0, 0, 0); + classtup = SearchSysCache(RELOID, + ObjectIdGetDatum(relid), + 0, 0, 0); if (!HeapTupleIsValid(classtup)) elog(ERROR, "cache lookup of relation %u failed", relid); classStruct = (Form_pg_class) GETSTRUCT(classtup); - return pstrdup(NameStr(classStruct->relname)); + result = pstrdup(NameStr(classStruct->relname)); + ReleaseSysCache(classtup); + return result; } diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 818bc6ab082..63e4d9b46d2 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.81 2000/11/10 09:38:21 inoue Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.82 2000/11/16 22:30:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -324,12 +324,15 @@ scalarltsel(PG_FUNCTION_ARGS) * Get left and right datatypes of the operator so we know what * type the constant is. */ - oprtuple = get_operator_tuple(opid); + oprtuple = SearchSysCache(OPEROID, + ObjectIdGetDatum(opid), + 0, 0, 0); if (!HeapTupleIsValid(oprtuple)) elog(ERROR, "scalarltsel: no tuple for operator %u", opid); ltype = ((Form_pg_operator) GETSTRUCT(oprtuple))->oprleft; rtype = ((Form_pg_operator) GETSTRUCT(oprtuple))->oprright; contype = (flag & SEL_RIGHT) ? rtype : ltype; + ReleaseSysCache(oprtuple); /* Now get info and stats about the attribute */ getattproperties(relid, attno, @@ -482,11 +485,14 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype) * Get left and right datatypes of the operator so we know what * type the attribute is. */ - oprtuple = get_operator_tuple(opid); + oprtuple = SearchSysCache(OPEROID, + ObjectIdGetDatum(opid), + 0, 0, 0); if (!HeapTupleIsValid(oprtuple)) elog(ERROR, "patternsel: no tuple for operator %u", opid); ltype = ((Form_pg_operator) GETSTRUCT(oprtuple))->oprleft; rtype = ((Form_pg_operator) GETSTRUCT(oprtuple))->oprright; + ReleaseSysCache(oprtuple); /* the right-hand const is type text for all supported operators */ Assert(rtype == TEXTOID); @@ -1189,10 +1195,10 @@ getattproperties(Oid relid, AttrNumber attnum, HeapTuple atp; Form_pg_attribute att_tup; - atp = SearchSysCacheTuple(ATTNUM, - ObjectIdGetDatum(relid), - Int16GetDatum(attnum), - 0, 0); + atp = SearchSysCache(ATTNUM, + ObjectIdGetDatum(relid), + Int16GetDatum(attnum), + 0, 0); if (!HeapTupleIsValid(atp)) elog(ERROR, "getattproperties: no attribute tuple %u %d", relid, (int) attnum); @@ -1202,6 +1208,8 @@ getattproperties(Oid relid, AttrNumber attnum, *typlen = att_tup->attlen; *typbyval = att_tup->attbyval; *typmod = att_tup->atttypmod; + + ReleaseSysCache(atp); } /* @@ -1250,11 +1258,10 @@ getattstatistics(Oid relid, * have at hand! (For example, we might have a '>' operator rather * than the '<' operator that will appear in staop.) */ - tuple = SearchSysCacheTupleCopy(STATRELID, - ObjectIdGetDatum(relid), - Int16GetDatum((int16) attnum), - 0, - 0); + tuple = SearchSysCache(STATRELID, + ObjectIdGetDatum(relid), + Int16GetDatum((int16) attnum), + 0, 0); if (!HeapTupleIsValid(tuple)) { /* no such stats entry */ @@ -1267,14 +1274,15 @@ getattstatistics(Oid relid, *commonfrac = ((Form_pg_statistic) GETSTRUCT(tuple))->stacommonfrac; /* Get the type input proc for the column datatype */ - typeTuple = SearchSysCacheTuple(TYPEOID, - ObjectIdGetDatum(typid), - 0, 0, 0); + typeTuple = SearchSysCache(TYPEOID, + ObjectIdGetDatum(typid), + 0, 0, 0); if (!HeapTupleIsValid(typeTuple)) elog(ERROR, "getattstatistics: Cache lookup failed for type %u", typid); fmgr_info(((Form_pg_type) GETSTRUCT(typeTuple))->typinput, &inputproc); typelem = ((Form_pg_type) GETSTRUCT(typeTuple))->typelem; + ReleaseSysCache(typeTuple); /* * Values are variable-length fields, so cannot access as struct @@ -1351,7 +1359,8 @@ getattstatistics(Oid relid, pfree(strval); } } - heap_freetuple(tuple); + + ReleaseSysCache(tuple); return true; } @@ -1966,16 +1975,11 @@ string_lessthan(const char *str1, const char *str2, Oid datatype) static Oid find_operator(const char *opname, Oid datatype) { - HeapTuple optup; - - optup = SearchSysCacheTuple(OPERNAME, - PointerGetDatum(opname), - ObjectIdGetDatum(datatype), - ObjectIdGetDatum(datatype), - CharGetDatum('b')); - if (!HeapTupleIsValid(optup)) - return InvalidOid; - return optup->t_data->t_oid; + return GetSysCacheOid(OPERNAME, + PointerGetDatum(opname), + ObjectIdGetDatum(datatype), + ObjectIdGetDatum(datatype), + CharGetDatum('b')); } /* diff --git a/src/backend/utils/adt/sets.c b/src/backend/utils/adt/sets.c index 9a5f05134cd..6f64847dcab 100644 --- a/src/backend/utils/adt/sets.c +++ b/src/backend/utils/adt/sets.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.33 2000/08/24 03:29:06 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.34 2000/11/16 22:30:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -77,9 +77,11 @@ SetDefine(char *querystr, char *typename) */ CommandCounterIncrement(); - tup = SearchSysCacheTuple(PROCOID, - ObjectIdGetDatum(setoid), - 0, 0, 0); + procrel = heap_openr(ProcedureRelationName, RowExclusiveLock); + + tup = SearchSysCache(PROCOID, + ObjectIdGetDatum(setoid), + 0, 0, 0); if (!HeapTupleIsValid(tup)) elog(ERROR, "SetDefine: unable to define set %s", querystr); @@ -105,25 +107,15 @@ SetDefine(char *querystr, char *typename) replNull[i] = ' '; /* change the pg_proc tuple */ - procrel = heap_openr(ProcedureRelationName, RowExclusiveLock); + newtup = heap_modifytuple(tup, + procrel, + replValue, + replNull, + repl); - tup = SearchSysCacheTuple(PROCOID, - ObjectIdGetDatum(setoid), - 0, 0, 0); - if (HeapTupleIsValid(tup)) - { - newtup = heap_modifytuple(tup, - procrel, - replValue, - replNull, - repl); + heap_update(procrel, &newtup->t_self, newtup, NULL); - heap_update(procrel, &tup->t_self, newtup, NULL); - - setoid = newtup->t_data->t_oid; - } - else - elog(ERROR, "SetDefine: could not find new set oid tuple"); + setoid = newtup->t_data->t_oid; if (RelationGetForm(procrel)->relhasindex) { @@ -133,9 +125,13 @@ SetDefine(char *querystr, char *typename) CatalogIndexInsert(idescs, Num_pg_proc_indices, procrel, newtup); CatalogCloseIndices(Num_pg_proc_indices, idescs); } - heap_close(procrel, RowExclusiveLock); + heap_freetuple(newtup); } + ReleaseSysCache(tup); + + heap_close(procrel, RowExclusiveLock); + return setoid; } |