31 #include "utils/array.h"
43 PGDLLEXPORT Datum
_pgr_prim(PG_FUNCTION_ARGS);
57 size_t *result_count) {
61 char *notice_msg = NULL;
64 char * fn_name =
get_name(1, fn_suffix, &err_msg);
70 size_t size_rootsArr = 0;
73 (*result_tuples) = NULL;
77 size_t total_edges = 0;
82 clock_t start_t = clock();
85 rootsArr, size_rootsArr,
102 if (*result_tuples) pfree(*result_tuples);
106 if (edges) pfree(edges);
107 if (log_msg) pfree(log_msg);
108 if (notice_msg) pfree(notice_msg);
109 if (err_msg) pfree(err_msg);
117 FuncCallContext *funcctx;
118 TupleDesc tuple_desc;
121 size_t result_count = 0;
123 if (SRF_IS_FIRSTCALL()) {
124 MemoryContext oldcontext;
125 funcctx = SRF_FIRSTCALL_INIT();
126 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
130 text_to_cstring(PG_GETARG_TEXT_P(0)),
131 PG_GETARG_ARRAYTYPE_P(1),
132 text_to_cstring(PG_GETARG_TEXT_P(2)),
139 #if PGSQL_VERSION > 95
140 funcctx->max_calls = result_count;
142 funcctx->max_calls = (uint32_t)result_count;
144 funcctx->user_fctx = result_tuples;
145 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
146 != TYPEFUNC_COMPOSITE) {
148 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
149 errmsg(
"function returning record called in context "
150 "that cannot accept type record")));
153 funcctx->tuple_desc = tuple_desc;
154 MemoryContextSwitchTo(oldcontext);
157 funcctx = SRF_PERCALL_SETUP();
158 tuple_desc = funcctx->tuple_desc;
159 result_tuples = (
pgr_mst_rt*) funcctx->user_fctx;
161 if (funcctx->call_cntr < funcctx->max_calls) {
168 values = palloc(num *
sizeof(Datum));
169 nulls = palloc(num *
sizeof(
bool));
173 for (i = 0; i < num; ++i) {
177 values[0] = Int64GetDatum(funcctx->call_cntr + 1);
178 values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].
depth);
179 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
from_v);
180 values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].
node);
181 values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
182 values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
183 values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].
agg_cost);
187 tuple = heap_form_tuple(tuple_desc, values, nulls);
188 result = HeapTupleGetDatum(tuple);
189 SRF_RETURN_NEXT(funcctx, result);
191 SRF_RETURN_DONE(funcctx);