33 #include "utils/array.h"
55 size_t *result_count) {
60 size_t size_start_vidsArr = 0;
61 int64_t *start_vidsArr = (int64_t *)
63 PGR_DBG(
"start_vidsArr size %ld ", size_start_vidsArr);
66 (*result_tuples) = NULL;
71 size_t total_edges = 0;
74 PGR_DBG(
"Total %ld edges in query:", total_edges);
76 if (total_edges == 0) {
84 clock_t start_t = clock();
86 char *notice_msg = NULL;
91 start_vidsArr, size_start_vidsArr,
102 time_msg(
" processing pgr_breadthFirstSearch", start_t, clock());
103 PGR_DBG(
"Returning %ld tuples", *result_count);
107 pfree(*result_tuples);
122 pfree(start_vidsArr);
127 FuncCallContext *funcctx;
128 TupleDesc tuple_desc;
132 size_t result_count = 0;
135 if (SRF_IS_FIRSTCALL()) {
136 MemoryContext oldcontext;
137 funcctx = SRF_FIRSTCALL_INIT();
138 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
152 text_to_cstring(PG_GETARG_TEXT_P(0)),
153 PG_GETARG_ARRAYTYPE_P(1),
161 #if PGSQL_VERSION > 95
162 funcctx->max_calls = result_count;
164 funcctx->max_calls = (uint32_t)result_count;
166 funcctx->user_fctx = result_tuples;
167 if (get_call_result_type(fcinfo, NULL, &tuple_desc) != TYPEFUNC_COMPOSITE) {
169 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
170 errmsg(
"function returning record called in context "
171 "that cannot accept type record")));
174 funcctx->tuple_desc = tuple_desc;
175 MemoryContextSwitchTo(oldcontext);
178 funcctx = SRF_PERCALL_SETUP();
179 tuple_desc = funcctx->tuple_desc;
180 result_tuples = (
pgr_mst_rt *)funcctx->user_fctx;
182 if (funcctx->call_cntr < funcctx->max_calls) {
200 values = palloc(numb *
sizeof(Datum));
201 nulls = palloc(numb *
sizeof(
bool));
204 for (i = 0; i < numb; ++i) {
208 values[0] = Int32GetDatum(funcctx->call_cntr + 1);
209 values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].
depth);
210 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
from_v);
211 values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].
node);
212 values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
213 values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
214 values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].
agg_cost);
218 tuple = heap_form_tuple(tuple_desc, values, nulls);
219 result = HeapTupleGetDatum(tuple);
220 SRF_RETURN_NEXT(funcctx, result);
228 SRF_RETURN_DONE(funcctx);