50 size_t *result_count) {
55 size_t total_tuples = 0;
58 if (total_tuples == 0) {
61 (*result_tuples) = NULL;
65 PGR_DBG(
"Total %ld tuples in query:", total_tuples);
69 char *notice_msg = NULL;
71 clock_t start_t = clock();
80 time_msg(
" processing Johnson", start_t, clock());
82 if (err_msg && (*result_tuples)) {
84 (*result_tuples) = NULL;
91 if (log_msg) pfree(log_msg);
92 if (notice_msg) pfree(notice_msg);
93 if (err_msg) pfree(err_msg);
103 FuncCallContext *funcctx;
104 TupleDesc tuple_desc;
110 size_t result_count = 0;
114 if (SRF_IS_FIRSTCALL()) {
115 MemoryContext oldcontext;
116 funcctx = SRF_FIRSTCALL_INIT();
117 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
128 text_to_cstring(PG_GETARG_TEXT_P(0)),
136 #if PGSQL_VERSION > 95
137 funcctx->max_calls = result_count;
139 funcctx->max_calls = (uint32_t)result_count;
141 funcctx->user_fctx = result_tuples;
142 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
143 != TYPEFUNC_COMPOSITE)
145 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
146 errmsg(
"function returning record called in context "
147 "that cannot accept type record")));
149 funcctx->tuple_desc = tuple_desc;
150 MemoryContextSwitchTo(oldcontext);
153 funcctx = SRF_PERCALL_SETUP();
154 tuple_desc = funcctx->tuple_desc;
157 if (funcctx->call_cntr < funcctx->max_calls) {
170 values = palloc(3 *
sizeof(Datum));
171 nulls = palloc(3 *
sizeof(
bool));
174 values[0] = Int64GetDatum(result_tuples[funcctx->call_cntr].
from_vid);
176 values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].
to_vid);
178 values[2] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
183 tuple = heap_form_tuple(tuple_desc, values, nulls);
184 result = HeapTupleGetDatum(tuple);
185 SRF_RETURN_NEXT(funcctx, result);
187 SRF_RETURN_DONE(funcctx);