36 #include "utils/array.h"
76 size_t *result_count) {
79 size_t size_rootsArr = 0;
83 (*result_tuples) = NULL;
87 size_t total_edges = 0;
91 clock_t start_t = clock();
93 char *notice_msg = NULL;
97 rootsArr, size_rootsArr,
108 time_msg(
"processing pgr_depthFirstSearch", start_t, clock());
110 if (err_msg && (*result_tuples)) {
111 pfree(*result_tuples);
112 (*result_tuples) = NULL;
118 if (log_msg) pfree(log_msg);
119 if (notice_msg) pfree(notice_msg);
120 if (err_msg) pfree(err_msg);
121 if (edges) pfree(edges);
122 if (rootsArr) pfree(rootsArr);
134 FuncCallContext *funcctx;
135 TupleDesc tuple_desc;
139 size_t result_count = 0;
142 if (SRF_IS_FIRSTCALL()) {
143 MemoryContext oldcontext;
144 funcctx = SRF_FIRSTCALL_INIT();
145 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
159 text_to_cstring(PG_GETARG_TEXT_P(0)),
160 PG_GETARG_ARRAYTYPE_P(1),
169 #if PGSQL_VERSION > 95
170 funcctx->max_calls = result_count;
172 funcctx->max_calls = (uint32_t)result_count;
174 funcctx->user_fctx = result_tuples;
175 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
176 != TYPEFUNC_COMPOSITE) {
178 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
179 errmsg(
"function returning record called in context "
180 "that cannot accept type record")));
183 funcctx->tuple_desc = tuple_desc;
184 MemoryContextSwitchTo(oldcontext);
187 funcctx = SRF_PERCALL_SETUP();
188 tuple_desc = funcctx->tuple_desc;
189 result_tuples = (
pgr_mst_rt*) funcctx->user_fctx;
191 if (funcctx->call_cntr < funcctx->max_calls) {
210 values = palloc(num *
sizeof(Datum));
211 nulls = palloc(num *
sizeof(
bool));
215 for (i = 0; i < num; ++i) {
219 values[0] = Int64GetDatum(funcctx->call_cntr + 1);
220 values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].
depth);
221 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
from_v);
222 values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].
node);
223 values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
224 values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
225 values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].
agg_cost);
229 tuple = heap_form_tuple(tuple_desc, values, nulls);
230 result = HeapTupleGetDatum(tuple);
231 SRF_RETURN_NEXT(funcctx, result);
233 SRF_RETURN_DONE(funcctx);