Pavel Stehule wrote: > > Hello > > can you send source code? There are two types of C SRF functions. One > returns row ro by row, second store returned rows and returns block. > What did you use? >
I had originally used the style that returns row by row, but after reading the page i created a new function which returns a block. This version runs slightly faster (12.5 seconds to run my test case) but it is still far slower than expected. A few notes on the code: getdata function returns an array with length 2*size, the first size elements are one colum the other size elements are the next column. I have timed the call getdata and determined it consumes on average around 30ms of my test case's run time. <code> PG_FUNCTION_INFO_V1(getTableFastHDF5); Datum getTableFastHDF5(PG_FUNCTION_ARGS) { /*{{{*/ /* Locals */ ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; FuncCallContext *fcc; TupleDesc tupdesc; Tuplestorestate *tupstore; MemoryContext per_query_ctx; MemoryContext oldcontext; AttInMetadata *attinmeta; int *data; int size; int i; if (!connections) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("No connections open, use openHDF5 to open a file first"))); data = getdata(textToStr(PG_GETARG_TEXT_P(0)), PG_GETARG_INT32(1), PG_GETARG_INT32(2), &size, TEMPORARY_CONTEXT); per_query_ctx = rsinfo->econtext->ecxt_per_query_memory; oldcontext = MemoryContextSwitchTo(per_query_ctx); tupdesc = rsinfo->expectedDesc; tupstore = tuplestore_begin_heap(true, false, SortMem); if (data == NULL) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("Could not find specified data in file"))); for (i = 0; i < size; i++) { /*{{{*/ Datum val[2]; bool nulls[2]; HeapTuple tup; MemoryContextSwitchTo(oldcontext); MemSet(nulls, false, 2 * sizeof(bool)); /* fill strings to be turned into tuple */ val[0] = Int32GetDatum(data[i]); val[1] = Int32GetDatum(data[i + size]); /* make tuple */ tup = heap_form_tuple(tupdesc, val, nulls); /* make tuple to datum so it can be returned */ MemoryContextSwitchTo(per_query_ctx); tuplestore_puttuple(tupstore, tup); /* return, but there is more to send */ /*}}}*/ } /* return and finish sending */ tuplestore_donestoring(tupstore); MemoryContextSwitchTo(oldcontext); rsinfo->returnMode = SFRM_Materialize; rsinfo->setResult = tupstore; rsinfo->setDesc = tupdesc; return (Datum) 0; /*}}}*/ } </code> -- View this message in context: http://www.nabble.com/Postgres-delays-function-returning-large-set-of-data-tp23853886p23891972.html Sent from the PostgreSQL - hackers mailing list archive at Nabble.com. -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers