aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/copy.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-11-16 22:30:52 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-11-16 22:30:52 +0000
commita933ee38bbb8dffbc48a3363a94ff6f2a9f7964d (patch)
tree1c32737389b2530e7152dc2287161b36d9001e8c /src/backend/commands/copy.c
parentcff23842a4c68301ddf34559c7af383bb5557054 (diff)
downloadpostgresql-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/commands/copy.c')
-rw-r--r--src/backend/commands/copy.c95
1 files changed, 47 insertions, 48 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 2877999500c..bbbb5aa2cfc 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.123 2000/11/12 00:36:56 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.124 2000/11/16 22:30:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -48,9 +48,9 @@
static void CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_print);
static void CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_print);
static Oid GetOutputFunction(Oid type);
-static Oid GetTypeElement(Oid type);
static Oid GetInputFunction(Oid type);
-static Oid IsTypeByVal(Oid type);
+static Oid GetTypeElement(Oid type);
+static bool IsTypeByVal(Oid type);
static void CopyReadNewline(FILE *fp, int *newline);
static char *CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline, char *null_print);
@@ -669,7 +669,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp,
continue;
}
#endif /* _DROP_COLUMN_HACK__ */
- byval[i] = (bool) IsTypeByVal(attr[i]->atttypid);
+ byval[i] = IsTypeByVal(attr[i]->atttypid);
}
lineno = 0;
@@ -893,65 +893,64 @@ static Oid
GetOutputFunction(Oid type)
{
HeapTuple typeTuple;
-
- typeTuple = SearchSysCacheTuple(TYPEOID,
- ObjectIdGetDatum(type),
- 0, 0, 0);
-
- if (HeapTupleIsValid(typeTuple))
- return (int) ((Form_pg_type) GETSTRUCT(typeTuple))->typoutput;
-
- elog(ERROR, "GetOutputFunction: Cache lookup of type %u failed", type);
- return InvalidOid;
+ Oid result;
+
+ typeTuple = SearchSysCache(TYPEOID,
+ ObjectIdGetDatum(type),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(typeTuple))
+ elog(ERROR, "GetOutputFunction: Cache lookup of type %u failed", type);
+ result = ((Form_pg_type) GETSTRUCT(typeTuple))->typoutput;
+ ReleaseSysCache(typeTuple);
+ return result;
}
static Oid
-GetTypeElement(Oid type)
+GetInputFunction(Oid type)
{
HeapTuple typeTuple;
-
- typeTuple = SearchSysCacheTuple(TYPEOID,
- ObjectIdGetDatum(type),
- 0, 0, 0);
-
- if (HeapTupleIsValid(typeTuple))
- return (int) ((Form_pg_type) GETSTRUCT(typeTuple))->typelem;
-
- elog(ERROR, "GetOutputFunction: Cache lookup of type %u failed", type);
- return InvalidOid;
+ Oid result;
+
+ typeTuple = SearchSysCache(TYPEOID,
+ ObjectIdGetDatum(type),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(typeTuple))
+ elog(ERROR, "GetInputFunction: Cache lookup of type %u failed", type);
+ result = ((Form_pg_type) GETSTRUCT(typeTuple))->typinput;
+ ReleaseSysCache(typeTuple);
+ return result;
}
static Oid
-GetInputFunction(Oid type)
+GetTypeElement(Oid type)
{
HeapTuple typeTuple;
-
- typeTuple = SearchSysCacheTuple(TYPEOID,
- ObjectIdGetDatum(type),
- 0, 0, 0);
-
- if (HeapTupleIsValid(typeTuple))
- return (int) ((Form_pg_type) GETSTRUCT(typeTuple))->typinput;
-
- elog(ERROR, "GetInputFunction: Cache lookup of type %u failed", type);
- return InvalidOid;
+ Oid result;
+
+ typeTuple = SearchSysCache(TYPEOID,
+ ObjectIdGetDatum(type),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(typeTuple))
+ elog(ERROR, "GetTypeElement: Cache lookup of type %u failed", type);
+ result = ((Form_pg_type) GETSTRUCT(typeTuple))->typelem;
+ ReleaseSysCache(typeTuple);
+ return result;
}
-static Oid
+static bool
IsTypeByVal(Oid type)
{
HeapTuple typeTuple;
-
- typeTuple = SearchSysCacheTuple(TYPEOID,
- ObjectIdGetDatum(type),
- 0, 0, 0);
-
- if (HeapTupleIsValid(typeTuple))
- return (int) ((Form_pg_type) GETSTRUCT(typeTuple))->typbyval;
-
- elog(ERROR, "GetInputFunction: Cache lookup of type %u failed", type);
-
- return InvalidOid;
+ bool result;
+
+ typeTuple = SearchSysCache(TYPEOID,
+ ObjectIdGetDatum(type),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(typeTuple))
+ elog(ERROR, "IsTypeByVal: Cache lookup of type %u failed", type);
+ result = ((Form_pg_type) GETSTRUCT(typeTuple))->typbyval;
+ ReleaseSysCache(typeTuple);
+ return result;
}