summaryrefslogtreecommitdiff
path: root/contrib/pgrowlocks/pgrowlocks.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/pgrowlocks/pgrowlocks.c')
-rw-r--r--contrib/pgrowlocks/pgrowlocks.c34
1 files changed, 4 insertions, 30 deletions
diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c
index d8946dc5107..713a165203e 100644
--- a/contrib/pgrowlocks/pgrowlocks.c
+++ b/contrib/pgrowlocks/pgrowlocks.c
@@ -66,42 +66,16 @@ pgrowlocks(PG_FUNCTION_ARGS)
{
text *relname = PG_GETARG_TEXT_PP(0);
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
- bool randomAccess;
- TupleDesc tupdesc;
- Tuplestorestate *tupstore;
AttInMetadata *attinmeta;
Relation rel;
RangeVar *relrv;
TableScanDesc scan;
HeapScanDesc hscan;
HeapTuple tuple;
- MemoryContext oldcontext;
AclResult aclresult;
char **values;
- /* check to see if caller supports us returning a tuplestore */
- if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("set-valued function called in context that cannot accept a set")));
- if (!(rsinfo->allowedModes & SFRM_Materialize))
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("materialize mode required, but it is not allowed in this context")));
-
- /* The tupdesc and tuplestore must be created in ecxt_per_query_memory */
- oldcontext = MemoryContextSwitchTo(rsinfo->econtext->ecxt_per_query_memory);
-
- if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
- elog(ERROR, "return type must be a row type");
-
- randomAccess = (rsinfo->allowedModes & SFRM_Materialize_Random) != 0;
- tupstore = tuplestore_begin_heap(randomAccess, false, work_mem);
- rsinfo->returnMode = SFRM_Materialize;
- rsinfo->setResult = tupstore;
- rsinfo->setDesc = tupdesc;
-
- MemoryContextSwitchTo(oldcontext);
+ SetSingleFuncCall(fcinfo, 0);
/* Access the table */
relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
@@ -140,9 +114,9 @@ pgrowlocks(PG_FUNCTION_ARGS)
scan = table_beginscan(rel, GetActiveSnapshot(), 0, NULL);
hscan = (HeapScanDesc) scan;
- attinmeta = TupleDescGetAttInMetadata(tupdesc);
+ attinmeta = TupleDescGetAttInMetadata(rsinfo->setDesc);
- values = (char **) palloc(tupdesc->natts * sizeof(char *));
+ values = (char **) palloc(rsinfo->setDesc->natts * sizeof(char *));
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
{
@@ -288,7 +262,7 @@ pgrowlocks(PG_FUNCTION_ARGS)
/* build a tuple */
tuple = BuildTupleFromCStrings(attinmeta, values);
- tuplestore_puttuple(tupstore, tuple);
+ tuplestore_puttuple(rsinfo->setResult, tuple);
}
else
{