diff options
author | Bruce Momjian <bruce@momjian.us> | 1998-08-19 02:04:17 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 1998-08-19 02:04:17 +0000 |
commit | 7971539020a344dce3a8b3b9b93ff4f10e2f823a (patch) | |
tree | 8dca0af0d3ac8d431bff8c0dec793fe9733a1ee9 /src/backend/utils/adt/regproc.c | |
parent | 31de2c9461dff3284ad61084c73eba093fa3f68e (diff) | |
download | postgresql-7971539020a344dce3a8b3b9b93ff4f10e2f823a.tar.gz postgresql-7971539020a344dce3a8b3b9b93ff4f10e2f823a.zip |
heap_fetch requires buffer pointer, must be released; heap_getnext
no longer returns buffer pointer, can be gotten from scan;
descriptor; bootstrap can create multi-key indexes;
pg_procname index now is multi-key index; oidint2, oidint4, oidname
are gone (must be removed from regression tests); use System Cache
rather than sequential scan in many places; heap_modifytuple no
longer takes buffer parameter; remove unused buffer parameter in
a few other functions; oid8 is not index-able; remove some use of
single-character variable names; cleanup Buffer variables usage
and scan descriptor looping; cleaned up allocation and freeing of
tuples; 18k lines of diff;
Diffstat (limited to 'src/backend/utils/adt/regproc.c')
-rw-r--r-- | src/backend/utils/adt/regproc.c | 253 |
1 files changed, 134 insertions, 119 deletions
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c index b3beb0b7cc5..227158748b3 100644 --- a/src/backend/utils/adt/regproc.c +++ b/src/backend/utils/adt/regproc.c @@ -1,4 +1,4 @@ -/*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * * regproc.c-- * Functions for the built-in type "RegProcedure". @@ -7,143 +7,190 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.21 1998/07/27 19:38:19 vadim Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.22 1998/08/19 02:03:04 momjian Exp $ * *------------------------------------------------------------------------- */ #include <string.h> #include "postgres.h" +#include "miscadmin.h" #include "access/heapam.h" #include "access/relscan.h" #include "fmgr.h" #include "utils/palloc.h" +#include "utils/syscache.h" #include "catalog/catname.h" +#include "catalog/pg_proc.h" +#include "catalog/pg_type.h" #include "utils/builtins.h" /* where function declarations go */ /***************************************************************************** * USER I/O ROUTINES * *****************************************************************************/ - + /* * regprocin - converts "proname" to proid * * proid of NULL signifies unknown */ int32 -regprocin(char *proname) +regprocin(char *pro_oid_name) { - Relation proc; - HeapScanDesc procscan; HeapTuple proctup; - ScanKeyData key; RegProcedure result = (Oid) 0; - bool isnull; - if (proname == NULL) + if (pro_oid_name == NULL) return (0); - proc = heap_openr(ProcedureRelationName); - if (!RelationIsValid(proc)) + + + if (!IsBootstrapProcessingMode()) { - elog(ERROR, "regprocin: could not open %s", - ProcedureRelationName); - return (0); + /* + * we need to use the oid because there can be multiple entries + * with the same name, i.e. 1323(int4eq) + */ + proctup = SearchSysCacheTuple(PROOID, + ObjectIdGetDatum(atoi(pro_oid_name)), + 0, 0, 0); + if (HeapTupleIsValid(proctup)) + result = (RegProcedure) proctup->t_oid; + else result = (RegProcedure) 0; } - ScanKeyEntryInitialize(&key, - (bits16) 0, - (AttrNumber) 1, - (RegProcedure) F_NAMEEQ, - (Datum) proname); - - procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key); - if (!HeapScanIsValid(procscan)) + else { + Relation proc; + HeapScanDesc procscan; + ScanKeyData key; + bool isnull; + + proc = heap_openr(ProcedureRelationName); + if (!RelationIsValid(proc)) + { + elog(ERROR, "regprocin: could not open %s", + ProcedureRelationName); + return (0); + } + ScanKeyEntryInitialize(&key, + (bits16) 0, + (AttrNumber) 1, + (RegProcedure) F_NAMEEQ, + (Datum) pro_oid_name); + + procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key); + if (!HeapScanIsValid(procscan)) + { + heap_close(proc); + elog(ERROR, "regprocin: could not being scan of %s", + ProcedureRelationName); + return (0); + } + proctup = heap_getnext(procscan, 0); + if (HeapTupleIsValid(proctup)) + { + result = (RegProcedure) heap_getattr(proctup, + ObjectIdAttributeNumber, + RelationGetTupleDescriptor(proc), + &isnull); + if (isnull) + elog(FATAL, "regprocin: null procedure %s", pro_oid_name); + } + else + result = (RegProcedure) 0; + + heap_endscan(procscan); heap_close(proc); - elog(ERROR, "regprocin: could not being scan of %s", - ProcedureRelationName); - return (0); - } - proctup = heap_getnext(procscan, 0, (Buffer *) NULL); - switch (HeapTupleIsValid(proctup)) - { - case 1: - result = (RegProcedure) heap_getattr(proctup, - ObjectIdAttributeNumber, - RelationGetTupleDescriptor(proc), - &isnull); - if (isnull) - elog(FATAL, "regprocin: null procedure %s", proname); - break; - case 0: - result = (RegProcedure) 0; + } + #ifdef EBUG - elog(DEBUG, "regprocin: no such procedure %s", proname); + elog(DEBUG, "regprocin: no such procedure %s", pro_oid_name); #endif /* defined(EBUG) */ - } - heap_endscan(procscan); - heap_close(proc); - return ((int32) result); + return (int32) result; } /* - * regprocout - converts proid to "proname" + * regprocout - converts proid to "pro_oid_name" */ char * regprocout(RegProcedure proid) { - Relation proc; - HeapScanDesc procscan; HeapTuple proctup; char *result; - ScanKeyData key; result = (char *) palloc(NAMEDATALEN); - proc = heap_openr(ProcedureRelationName); - if (!RelationIsValid(proc)) - { - elog(ERROR, "regprocout: could not open %s", - ProcedureRelationName); - return (0); - } - ScanKeyEntryInitialize(&key, - (bits16) 0, - (AttrNumber) ObjectIdAttributeNumber, - (RegProcedure) F_INT4EQ, - (Datum) proid); - - procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key); - if (!HeapScanIsValid(procscan)) + + if (!IsBootstrapProcessingMode()) { - heap_close(proc); - elog(ERROR, "regprocout: could not being scan of %s", - ProcedureRelationName); - return (0); + proctup = SearchSysCacheTuple(PROOID, + ObjectIdGetDatum(proid), + 0, 0, 0); + + if (HeapTupleIsValid(proctup)) + { + char *s; + + s = ((Form_pg_proc) GETSTRUCT(proctup))->proname.data; + snprintf(result, NAMEDATALEN, "%d(%s)", proid, s); + } + else + { + result[0] = '-'; + result[1] = '\0'; + } } - proctup = heap_getnext(procscan, 0, (Buffer *) NULL); - switch (HeapTupleIsValid(proctup)) + else { + Relation proc; + HeapScanDesc procscan; + ScanKeyData key; + + proc = heap_openr(ProcedureRelationName); + if (!RelationIsValid(proc)) + { + elog(ERROR, "regprocout: could not open %s", + ProcedureRelationName); + return (0); + } + ScanKeyEntryInitialize(&key, + (bits16) 0, + (AttrNumber) ObjectIdAttributeNumber, + (RegProcedure) F_INT4EQ, + (Datum) proid); + + procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key); + if (!HeapScanIsValid(procscan)) + { + heap_close(proc); + elog(ERROR, "regprocout: could not being scan of %s", + ProcedureRelationName); + return (0); + } + proctup = heap_getnext(procscan, 0); + if (HeapTupleIsValid(proctup)) + { char *s; bool isnull; - case 1: s = (char *) heap_getattr(proctup, 1, RelationGetTupleDescriptor(proc), &isnull); if (!isnull) - { StrNCpy(result, s, NAMEDATALEN); - break; - } - elog(FATAL, "regprocout: null procedure %d", proid); - /* FALLTHROUGH */ - case 0: - result[0] = '-'; - result[1] = '\0'; + else + elog(FATAL, "regprocout: null procedure %d", proid); + } + else + { + result[0] = '-'; + result[1] = '\0'; + } + heap_endscan(procscan); + heap_close(proc); + return (result); + } + #ifdef EBUG elog(DEBUG, "regprocout: no such procedure %d", proid); #endif /* defined(EBUG) */ - } - heap_endscan(procscan); - heap_close(proc); return (result); } @@ -153,11 +200,8 @@ regprocout(RegProcedure proid) text * oid8types(Oid (*oidArray)[]) { - Relation type; - HeapScanDesc typescan; HeapTuple typetup; text *result; - ScanKeyData key; int num; Oid *sp; @@ -170,55 +214,26 @@ oid8types(Oid (*oidArray)[]) result = (text *) palloc(NAMEDATALEN * 8 + 8 + VARHDRSZ); *VARDATA(result) = '\0'; - type = heap_openr(TypeRelationName); - if (!RelationIsValid(type)) - { - elog(ERROR, "int8typeout: could not open %s", - TypeRelationName); - return (0); - } sp = *oidArray; for (num = 8; num != 0; num--, sp++) { if (*sp != InvalidOid) { - ScanKeyEntryInitialize(&key, - (bits16) 0, - (AttrNumber) ObjectIdAttributeNumber, - (RegProcedure) F_INT4EQ, - (Datum) *sp); - - typescan = heap_beginscan(type, 0, SnapshotNow, 1, &key); - if (!HeapScanIsValid(typescan)) - { - heap_close(type); - elog(ERROR, "int8typeout: could not being scan of %s", - TypeRelationName); - return (0); - } - typetup = heap_getnext(typescan, 0, (Buffer *) NULL); + typetup = SearchSysCacheTuple(TYPOID, + ObjectIdGetDatum(*sp), + 0, 0, 0); if (HeapTupleIsValid(typetup)) { char *s; - bool isnull; - s = (char *) heap_getattr(typetup, 1, - RelationGetTupleDescriptor(type), &isnull); - if (!isnull) - { - StrNCpy(VARDATA(result) + strlen(VARDATA(result)), s, + s = ((TypeTupleForm) GETSTRUCT(typetup))->typname.data; + StrNCpy(VARDATA(result) + strlen(VARDATA(result)), s, NAMEDATALEN); - strcat(VARDATA(result), " "); - } - else - elog(FATAL, "int8typeout: null procedure %d", *sp); - /* FALLTHROUGH */ + strcat(VARDATA(result), " "); } - heap_endscan(typescan); } } - heap_close(type); VARSIZE(result) = strlen(VARDATA(result)) + VARHDRSZ; return (result); } |