summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-04-01 21:28:47 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-04-01 21:28:47 +0000
commit375369acd1c621bdc683c58bc9c31d4e79d14849 (patch)
treef29974842cea4105c92da6031bac736ddf5f833a /contrib
parent8590a62b75d3dba24609eb46b34fac13ed881d9e (diff)
downloadpostgresql-375369acd1c621bdc683c58bc9c31d4e79d14849.tar.gz
Replace TupleTableSlot convention for whole-row variables and function
results with tuples as ordinary varlena Datums. This commit does not in itself do much for us, except eliminate the horrid memory leak associated with evaluation of whole-row variables. However, it lays the groundwork for allowing composite types as table columns, and perhaps some other useful features as well. Per my proposal of a few days ago.
Diffstat (limited to 'contrib')
-rw-r--r--contrib/dblink/dblink.c45
-rw-r--r--contrib/intagg/int_aggregate.c1
-rw-r--r--contrib/pgstattuple/pgstattuple.c10
-rw-r--r--contrib/tablefunc/tablefunc.c20
-rw-r--r--contrib/tsearch2/ts_stat.c3
-rw-r--r--contrib/tsearch2/wparser.c6
6 files changed, 25 insertions, 60 deletions
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index ac941598be..4a521a0fac 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -447,7 +447,6 @@ dblink_fetch(PG_FUNCTION_ARGS)
TupleDesc tupdesc = NULL;
int call_cntr;
int max_calls;
- TupleTableSlot *slot;
AttInMetadata *attinmeta;
char *msg;
PGresult *res = NULL;
@@ -566,9 +565,10 @@ dblink_fetch(PG_FUNCTION_ARGS)
if (functyptype == 'c')
tupdesc = TypeGetTupleDesc(functypeid, NIL);
- else if (functyptype == 'p' && functypeid == RECORDOID)
+ else if (functypeid == RECORDOID)
{
- if (!rsinfo || !IsA(rsinfo, ReturnSetInfo))
+ if (!rsinfo || !IsA(rsinfo, ReturnSetInfo) ||
+ rsinfo->expectedDesc == NULL)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("function returning record called in context "
@@ -582,8 +582,6 @@ dblink_fetch(PG_FUNCTION_ARGS)
elog(ERROR, "return type must be a row type");
/* store needed metadata for subsequent calls */
- slot = TupleDescGetSlot(tupdesc);
- funcctx->slot = slot;
attinmeta = TupleDescGetAttInMetadata(tupdesc);
funcctx->attinmeta = attinmeta;
@@ -599,8 +597,6 @@ dblink_fetch(PG_FUNCTION_ARGS)
call_cntr = funcctx->call_cntr;
max_calls = funcctx->max_calls;
- slot = funcctx->slot;
-
res = (PGresult *) funcctx->user_fctx;
attinmeta = funcctx->attinmeta;
tupdesc = attinmeta->tupdesc;
@@ -626,7 +622,7 @@ dblink_fetch(PG_FUNCTION_ARGS)
tuple = BuildTupleFromCStrings(attinmeta, values);
/* make the tuple into a datum */
- result = TupleGetDatum(slot, tuple);
+ result = HeapTupleGetDatum(tuple);
SRF_RETURN_NEXT(funcctx, result);
}
@@ -649,7 +645,6 @@ dblink_record(PG_FUNCTION_ARGS)
TupleDesc tupdesc = NULL;
int call_cntr;
int max_calls;
- TupleTableSlot *slot;
AttInMetadata *attinmeta;
char *msg;
PGresult *res = NULL;
@@ -741,7 +736,7 @@ dblink_record(PG_FUNCTION_ARGS)
/* need a tuple descriptor representing one TEXT column */
tupdesc = CreateTemplateTupleDesc(1, false);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "status",
- TEXTOID, -1, 0, false);
+ TEXTOID, -1, 0);
/*
* and save a copy of the command status string to return as
@@ -776,9 +771,10 @@ dblink_record(PG_FUNCTION_ARGS)
{
if (functyptype == 'c')
tupdesc = TypeGetTupleDesc(functypeid, NIL);
- else if (functyptype == 'p' && functypeid == RECORDOID)
+ else if (functypeid == RECORDOID)
{
- if (!rsinfo || !IsA(rsinfo, ReturnSetInfo))
+ if (!rsinfo || !IsA(rsinfo, ReturnSetInfo) ||
+ rsinfo->expectedDesc == NULL)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("function returning record called in context "
@@ -793,8 +789,6 @@ dblink_record(PG_FUNCTION_ARGS)
}
/* store needed metadata for subsequent calls */
- slot = TupleDescGetSlot(tupdesc);
- funcctx->slot = slot;
attinmeta = TupleDescGetAttInMetadata(tupdesc);
funcctx->attinmeta = attinmeta;
@@ -810,8 +804,6 @@ dblink_record(PG_FUNCTION_ARGS)
call_cntr = funcctx->call_cntr;
max_calls = funcctx->max_calls;
- slot = funcctx->slot;
-
res = (PGresult *) funcctx->user_fctx;
attinmeta = funcctx->attinmeta;
tupdesc = attinmeta->tupdesc;
@@ -846,7 +838,7 @@ dblink_record(PG_FUNCTION_ARGS)
tuple = BuildTupleFromCStrings(attinmeta, values);
/* make the tuple into a datum */
- result = TupleGetDatum(slot, tuple);
+ result = HeapTupleGetDatum(tuple);
SRF_RETURN_NEXT(funcctx, result);
}
@@ -925,7 +917,7 @@ dblink_exec(PG_FUNCTION_ARGS)
/* need a tuple descriptor representing one TEXT column */
tupdesc = CreateTemplateTupleDesc(1, false);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "status",
- TEXTOID, -1, 0, false);
+ TEXTOID, -1, 0);
/*
* and save a copy of the command status string to return as our
@@ -939,7 +931,7 @@ dblink_exec(PG_FUNCTION_ARGS)
/* need a tuple descriptor representing one TEXT column */
tupdesc = CreateTemplateTupleDesc(1, false);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "status",
- TEXTOID, -1, 0, false);
+ TEXTOID, -1, 0);
/*
* and save a copy of the command status string to return as our
@@ -978,7 +970,6 @@ dblink_get_pkey(PG_FUNCTION_ARGS)
FuncCallContext *funcctx;
int32 call_cntr;
int32 max_calls;
- TupleTableSlot *slot;
AttInMetadata *attinmeta;
MemoryContext oldcontext;
@@ -1010,15 +1001,9 @@ dblink_get_pkey(PG_FUNCTION_ARGS)
*/
tupdesc = CreateTemplateTupleDesc(2, false);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "position",
- INT4OID, -1, 0, false);
+ INT4OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "colname",
- TEXTOID, -1, 0, false);
-
- /* allocate a slot for a tuple with this tupdesc */
- slot = TupleDescGetSlot(tupdesc);
-
- /* assign slot to function context */
- funcctx->slot = slot;
+ TEXTOID, -1, 0);
/*
* Generate attribute metadata needed later to produce tuples from
@@ -1053,8 +1038,6 @@ dblink_get_pkey(PG_FUNCTION_ARGS)
call_cntr = funcctx->call_cntr;
max_calls = funcctx->max_calls;
- slot = funcctx->slot;
-
results = (char **) funcctx->user_fctx;
attinmeta = funcctx->attinmeta;
@@ -1075,7 +1058,7 @@ dblink_get_pkey(PG_FUNCTION_ARGS)
tuple = BuildTupleFromCStrings(attinmeta, values);
/* make the tuple into a datum */
- result = TupleGetDatum(slot, tuple);
+ result = HeapTupleGetDatum(tuple);
SRF_RETURN_NEXT(funcctx, result);
}
diff --git a/contrib/intagg/int_aggregate.c b/contrib/intagg/int_aggregate.c
index 2bb06ff73a..bd03f5c0c3 100644
--- a/contrib/intagg/int_aggregate.c
+++ b/contrib/intagg/int_aggregate.c
@@ -25,7 +25,6 @@
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "executor/executor.h"
-#include "utils/sets.h"
#include "utils/syscache.h"
#include "access/tupmacs.h"
#include "access/xact.h"
diff --git a/contrib/pgstattuple/pgstattuple.c b/contrib/pgstattuple/pgstattuple.c
index abc2249aed..ca08261856 100644
--- a/contrib/pgstattuple/pgstattuple.c
+++ b/contrib/pgstattuple/pgstattuple.c
@@ -1,5 +1,5 @@
/*
- * $PostgreSQL: pgsql/contrib/pgstattuple/pgstattuple.c,v 1.13 2003/11/29 19:51:35 pgsql Exp $
+ * $PostgreSQL: pgsql/contrib/pgstattuple/pgstattuple.c,v 1.14 2004/04/01 21:28:43 tgl Exp $
*
* Copyright (c) 2001,2002 Tatsuo Ishii
*
@@ -111,7 +111,6 @@ pgstattuple_real(Relation rel)
uint64 free_space = 0; /* free/reusable space in bytes */
double free_percent; /* free/reusable space in % */
TupleDesc tupdesc;
- TupleTableSlot *slot;
AttInMetadata *attinmeta;
char **values;
int i;
@@ -122,9 +121,6 @@ pgstattuple_real(Relation rel)
*/
tupdesc = RelationNameGetTupleDesc(DUMMY_TUPLE);
- /* allocate a slot for a tuple with this tupdesc */
- slot = TupleDescGetSlot(tupdesc);
-
/*
* Generate attribute metadata needed later to produce tuples from raw
* C strings
@@ -192,7 +188,7 @@ pgstattuple_real(Relation rel)
}
/*
- * Prepare a values array for storage in our slot. This should be an
+ * Prepare a values array for constructing the tuple. This should be an
* array of C strings which will be processed later by the appropriate
* "in" functions.
*/
@@ -214,7 +210,7 @@ pgstattuple_real(Relation rel)
tuple = BuildTupleFromCStrings(attinmeta, values);
/* make the tuple into a datum */
- result = TupleGetDatum(slot, tuple);
+ result = HeapTupleGetDatum(tuple);
/* Clean up */
for (i = 0; i < NCOLUMNS; i++)
diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c
index 622164b91b..3eccebf476 100644
--- a/contrib/tablefunc/tablefunc.c
+++ b/contrib/tablefunc/tablefunc.c
@@ -351,7 +351,6 @@ crosstab(PG_FUNCTION_ARGS)
TupleDesc ret_tupdesc;
int call_cntr;
int max_calls;
- TupleTableSlot *slot;
AttInMetadata *attinmeta;
SPITupleTable *spi_tuptable = NULL;
TupleDesc spi_tupdesc;
@@ -429,10 +428,10 @@ crosstab(PG_FUNCTION_ARGS)
if (functyptype == 'c')
{
- /* Build a tuple description for a functypeid tuple */
+ /* Build a tuple description for a named composite type */
tupdesc = TypeGetTupleDesc(functypeid, NIL);
}
- else if (functyptype == 'p' && functypeid == RECORDOID)
+ else if (functypeid == RECORDOID)
{
if (fcinfo->nargs != 2)
ereport(ERROR,
@@ -461,12 +460,6 @@ crosstab(PG_FUNCTION_ARGS)
errmsg("return and sql tuple descriptions are " \
"incompatible")));
- /* allocate a slot for a tuple with this tupdesc */
- slot = TupleDescGetSlot(tupdesc);
-
- /* assign slot to function context */
- funcctx->slot = slot;
-
/*
* Generate attribute metadata needed later to produce tuples from
* raw C strings
@@ -499,9 +492,6 @@ crosstab(PG_FUNCTION_ARGS)
call_cntr = funcctx->call_cntr;
max_calls = funcctx->max_calls;
- /* return slot for our tuple */
- slot = funcctx->slot;
-
/* user context info */
fctx = (crosstab_fctx *) funcctx->user_fctx;
lastrowid = fctx->lastrowid;
@@ -621,7 +611,7 @@ crosstab(PG_FUNCTION_ARGS)
tuple = BuildTupleFromCStrings(attinmeta, values);
/* make the tuple into a datum */
- result = TupleGetDatum(slot, tuple);
+ result = HeapTupleGetDatum(tuple);
/* Clean up */
for (i = 0; i < num_categories + 1; i++)
@@ -1675,7 +1665,7 @@ make_crosstab_tupledesc(TupleDesc spi_tupdesc, int num_categories)
strcpy(attname, "rowname");
TupleDescInitEntry(tupdesc, attnum, attname, sql_atttypid,
- -1, 0, false);
+ -1, 0);
/* now the category values columns */
sql_attr = spi_tupdesc->attrs[2];
@@ -1687,7 +1677,7 @@ make_crosstab_tupledesc(TupleDesc spi_tupdesc, int num_categories)
sprintf(attname, "category_%d", i + 1);
TupleDescInitEntry(tupdesc, attnum, attname, sql_atttypid,
- -1, 0, false);
+ -1, 0);
}
return tupdesc;
diff --git a/contrib/tsearch2/ts_stat.c b/contrib/tsearch2/ts_stat.c
index 732f25b6bd..a6518e3439 100644
--- a/contrib/tsearch2/ts_stat.c
+++ b/contrib/tsearch2/ts_stat.c
@@ -303,7 +303,6 @@ ts_setup_firstcall(FuncCallContext *funcctx, tsstat * stat)
memcpy(st->stat, stat, stat->len);
funcctx->user_fctx = (void *) st;
tupdesc = RelationNameGetTupleDesc("statinfo");
- funcctx->slot = TupleDescGetSlot(tupdesc);
funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
MemoryContextSwitchTo(oldcontext);
}
@@ -334,7 +333,7 @@ ts_process_call(FuncCallContext *funcctx)
(values[0])[entry->len] = '\0';
tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
- result = TupleGetDatum(funcctx->slot, tuple);
+ result = HeapTupleGetDatum(tuple);
pfree(values[0]);
st->cur++;
diff --git a/contrib/tsearch2/wparser.c b/contrib/tsearch2/wparser.c
index b7e45e5188..9c3c443048 100644
--- a/contrib/tsearch2/wparser.c
+++ b/contrib/tsearch2/wparser.c
@@ -187,7 +187,6 @@ setup_firstcall(FuncCallContext *funcctx, Oid prsid)
);
funcctx->user_fctx = (void *) st;
tupdesc = RelationNameGetTupleDesc("tokentype");
- funcctx->slot = TupleDescGetSlot(tupdesc);
funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
MemoryContextSwitchTo(oldcontext);
}
@@ -211,7 +210,7 @@ process_call(FuncCallContext *funcctx)
values[2] = st->list[st->cur].descr;
tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
- result = TupleGetDatum(funcctx->slot, tuple);
+ result = HeapTupleGetDatum(tuple);
pfree(values[1]);
pfree(values[2]);
@@ -391,7 +390,6 @@ prs_setup_firstcall(FuncCallContext *funcctx, int prsid, text *txt)
funcctx->user_fctx = (void *) st;
tupdesc = RelationNameGetTupleDesc("tokenout");
- funcctx->slot = TupleDescGetSlot(tupdesc);
funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
MemoryContextSwitchTo(oldcontext);
}
@@ -413,7 +411,7 @@ prs_process_call(FuncCallContext *funcctx)
sprintf(tid, "%d", st->list[st->cur].type);
values[1] = st->list[st->cur].lexem;
tuple = BuildTupleFromCStrings(funcctx->attinmeta, values);
- result = TupleGetDatum(funcctx->slot, tuple);
+ result = HeapTupleGetDatum(tuple);
pfree(values[1]);
st->cur++;