diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-01-23 03:43:24 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-01-23 03:43:24 +0000 |
commit | 27fee810ff9968a1034fea4bba4cd8d078c5d2d1 (patch) | |
tree | 24062ec2af7290f3d443e65c044c50e0ef1431be /src/backend/utils/cache/lsyscache.c | |
parent | 1161077e9774496273999183eb29ea4b46d52f66 (diff) | |
download | postgresql-27fee810ff9968a1034fea4bba4cd8d078c5d2d1.tar.gz postgresql-27fee810ff9968a1034fea4bba4cd8d078c5d2d1.zip |
Replace SearchSysCacheGetAttribute with SysCacheGetAttr, which fetches
an attribute of a tuple previously fetched with SearchSysCacheTuple.
This avoids a lot of redundant cache lookups, particularly in selfuncs.c.
Also, remove SearchSysCacheStruct, which was unused and grotty.
Diffstat (limited to 'src/backend/utils/cache/lsyscache.c')
-rw-r--r-- | src/backend/utils/cache/lsyscache.c | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 1c34486b749..406c476182b 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -6,7 +6,7 @@ * Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.37 1999/12/31 03:18:43 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.38 2000/01/23 03:43:24 tgl Exp $ * * NOTES * Eventually, the index information should go through here, too. @@ -617,35 +617,15 @@ get_typalign(Oid typid) Datum get_typdefault(Oid typid) { - struct varlena *typDefault; - int32 dataSize; HeapTuple typeTuple; Form_pg_type type; + struct varlena *typDefault; + bool isNull; + int32 dataSize; int32 typLen; bool typByVal; Datum returnValue; - /* - * First, see if there is a non-null typdefault field (usually there isn't) - */ - typDefault = (struct varlena *) - SearchSysCacheGetAttribute(TYPEOID, - Anum_pg_type_typdefault, - ObjectIdGetDatum(typid), - 0, 0, 0); - - if (typDefault == NULL) - return PointerGetDatum(NULL); - - dataSize = VARSIZE(typDefault) - VARHDRSZ; - - /* - * Need the type's length and byVal fields. - * - * XXX silly to repeat the syscache search that SearchSysCacheGetAttribute - * just did --- but at present this path isn't taken often enough to - * make it worth fixing. - */ typeTuple = SearchSysCacheTuple(TYPEOID, ObjectIdGetDatum(typid), 0, 0, 0); @@ -654,6 +634,22 @@ get_typdefault(Oid typid) elog(ERROR, "get_typdefault: failed to lookup type %u", typid); type = (Form_pg_type) GETSTRUCT(typeTuple); + + /* + * First, see if there is a non-null typdefault field (usually there isn't) + */ + typDefault = (struct varlena *) SysCacheGetAttr(TYPEOID, + typeTuple, + Anum_pg_type_typdefault, + &isNull); + + if (isNull) + return PointerGetDatum(NULL); + + /* + * Otherwise, extract/copy the value. + */ + dataSize = VARSIZE(typDefault) - VARHDRSZ; typLen = type->typlen; typByVal = type->typbyval; |