33 #include "utils/array.h"
52 char *combinations_sql,
59 size_t *result_count) {
64 size_t size_start_vidsArr = 0;
65 int64_t* start_vidsArr = NULL;
67 size_t size_end_vidsArr = 0;
68 int64_t* end_vidsArr = NULL;
70 size_t total_combinations = 0;
74 start_vidsArr = (int64_t*)
76 end_vidsArr = (int64_t*)
78 }
else if (combinations_sql) {
80 if (total_combinations == 0) {
88 (*result_tuples) = NULL;
93 size_t total_edges = 0;
96 PGR_DBG(
"Total %ld edges in query:", total_edges);
98 if (total_edges == 0) {
99 if (end_vidsArr) pfree(end_vidsArr);
100 if (start_vidsArr) pfree(start_vidsArr);
105 PGR_DBG(
"Starting processing");
106 clock_t start_t = clock();
107 char *log_msg = NULL;
108 char *notice_msg = NULL;
109 char *err_msg = NULL;
115 start_vidsArr, size_start_vidsArr,
116 end_vidsArr, size_end_vidsArr,
127 time_msg(
" processing pgr_bellman_ford", start_t, clock());
128 PGR_DBG(
"Returning %ld tuples", *result_count);
131 if (*result_tuples) pfree(*result_tuples);
136 if (edges) pfree(edges);
137 if (log_msg) pfree(log_msg);
138 if (notice_msg) pfree(notice_msg);
139 if (err_msg) pfree(err_msg);
141 if (end_vidsArr) pfree(end_vidsArr);
142 if (start_vidsArr) pfree(start_vidsArr);
148 FuncCallContext *funcctx;
149 TupleDesc tuple_desc;
153 size_t result_count = 0;
156 if (SRF_IS_FIRSTCALL()) {
157 MemoryContext oldcontext;
158 funcctx = SRF_FIRSTCALL_INIT();
159 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
163 if (PG_NARGS() == 5) {
168 text_to_cstring(PG_GETARG_TEXT_P(0)),
170 PG_GETARG_ARRAYTYPE_P(1),
171 PG_GETARG_ARRAYTYPE_P(2),
177 }
else if (PG_NARGS() == 4) {
182 text_to_cstring(PG_GETARG_TEXT_P(0)),
183 text_to_cstring(PG_GETARG_TEXT_P(1)),
195 #if PGSQL_VERSION > 95
196 funcctx->max_calls = result_count;
198 funcctx->max_calls = (uint32_t)result_count;
200 funcctx->user_fctx = result_tuples;
201 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
202 != TYPEFUNC_COMPOSITE) {
204 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
205 errmsg(
"function returning record called in context "
206 "that cannot accept type record")));
209 funcctx->tuple_desc = tuple_desc;
210 MemoryContextSwitchTo(oldcontext);
213 funcctx = SRF_PERCALL_SETUP();
214 tuple_desc = funcctx->tuple_desc;
217 if (funcctx->call_cntr < funcctx->max_calls) {
236 values = palloc(numb *
sizeof(Datum));
237 nulls = palloc(numb *
sizeof(
bool));
241 for (i = 0; i < numb; ++i) {
245 values[0] = Int32GetDatum(funcctx->call_cntr + 1);
246 values[1] = Int32GetDatum(result_tuples[funcctx->call_cntr].
seq);
247 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
start_id);
248 values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].
end_id);
249 values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].
node);
250 values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
251 values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
252 values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].
agg_cost);
256 tuple = heap_form_tuple(tuple_desc, values, nulls);
257 result = HeapTupleGetDatum(tuple);
258 SRF_RETURN_NEXT(funcctx, result);
266 SRF_RETURN_DONE(funcctx);