32 #include "utils/array.h"
58 size_t *result_count) {
62 char *notice_msg = NULL;
65 char * fn_name =
get_name(0, fn_suffix, &err_msg);
71 size_t size_rootsArr = 0;
74 (*result_tuples) = NULL;
78 size_t total_edges = 0;
82 clock_t start_t = clock();
85 rootsArr, size_rootsArr,
99 if (*result_tuples) pfree(*result_tuples);
103 if (edges) pfree(edges);
104 if (log_msg) pfree(log_msg);
105 if (notice_msg) pfree(notice_msg);
106 if (err_msg) pfree(err_msg);
112 FuncCallContext *funcctx;
113 TupleDesc tuple_desc;
116 size_t result_count = 0;
118 if (SRF_IS_FIRSTCALL()) {
119 MemoryContext oldcontext;
120 funcctx = SRF_FIRSTCALL_INIT();
121 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
126 text_to_cstring(PG_GETARG_TEXT_P(0)),
127 PG_GETARG_ARRAYTYPE_P(1),
128 text_to_cstring(PG_GETARG_TEXT_P(2)),
134 #if PGSQL_VERSION > 95
135 funcctx->max_calls = result_count;
137 funcctx->max_calls = (uint32_t)result_count;
139 funcctx->user_fctx = result_tuples;
140 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
141 != TYPEFUNC_COMPOSITE) {
143 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
144 errmsg(
"function returning record called in context "
145 "that cannot accept type record")));
148 funcctx->tuple_desc = tuple_desc;
149 MemoryContextSwitchTo(oldcontext);
152 funcctx = SRF_PERCALL_SETUP();
153 tuple_desc = funcctx->tuple_desc;
154 result_tuples = (
pgr_mst_rt*) funcctx->user_fctx;
156 if (funcctx->call_cntr < funcctx->max_calls) {
163 values = palloc(num *
sizeof(Datum));
164 nulls = palloc(num *
sizeof(
bool));
168 for (i = 0; i < num; ++i) {
172 values[0] = Int64GetDatum(funcctx->call_cntr + 1);
173 values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].
depth);
174 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
from_v);
175 values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].
node);
176 values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
177 values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
178 values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].
agg_cost);
181 tuple = heap_form_tuple(tuple_desc, values, nulls);
182 result = HeapTupleGetDatum(tuple);
183 SRF_RETURN_NEXT(funcctx, result);
185 SRF_RETURN_DONE(funcctx);