33 #include "utils/array.h"
51 char* combinations_sql,
57 size_t *result_count) {
67 size_t size_start_vidsArr = 0;
68 int64_t* start_vidsArr = NULL;
70 size_t size_end_vidsArr = 0;
71 int64_t* end_vidsArr = NULL;
73 size_t total_combinations = 0;
77 start_vidsArr = (int64_t*)
79 end_vidsArr = (int64_t*)
81 }
else if (combinations_sql) {
83 if (total_combinations == 0) {
91 (*result_tuples) = NULL;
96 size_t total_edges = 0;
99 PGR_DBG(
"Total %ld edges in query:", total_edges);
101 if (total_edges == 0) {
107 PGR_DBG(
"Starting processing");
108 clock_t start_t = clock();
109 char *log_msg = NULL;
110 char *notice_msg = NULL;
111 char *err_msg = NULL;
117 start_vidsArr, size_start_vidsArr,
118 end_vidsArr, size_end_vidsArr,
128 time_msg(
" processing pgr_dagShortestPath", start_t, clock());
129 PGR_DBG(
"Returning %ld tuples", *result_count);
132 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);
142 if (end_vidsArr) pfree(end_vidsArr);
143 if (start_vidsArr) pfree(start_vidsArr);
151 FuncCallContext *funcctx;
152 TupleDesc tuple_desc;
155 size_t result_count = 0;
157 if (SRF_IS_FIRSTCALL()) {
158 MemoryContext oldcontext;
159 funcctx = SRF_FIRSTCALL_INIT();
160 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
164 if (PG_NARGS() == 5) {
169 text_to_cstring(PG_GETARG_TEXT_P(0)),
171 PG_GETARG_ARRAYTYPE_P(1),
172 PG_GETARG_ARRAYTYPE_P(2),
178 }
else if (PG_NARGS() == 4) {
183 text_to_cstring(PG_GETARG_TEXT_P(0)),
184 text_to_cstring(PG_GETARG_TEXT_P(1)),
196 #if PGSQL_VERSION > 95
197 funcctx->max_calls = result_count;
199 funcctx->max_calls = (uint32_t)result_count;
201 funcctx->user_fctx = result_tuples;
202 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
203 != TYPEFUNC_COMPOSITE) {
205 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
206 errmsg(
"function returning record called in context "
207 "that cannot accept type record")));
210 funcctx->tuple_desc = tuple_desc;
211 MemoryContextSwitchTo(oldcontext);
214 funcctx = SRF_PERCALL_SETUP();
215 tuple_desc = funcctx->tuple_desc;
218 if (funcctx->call_cntr < funcctx->max_calls) {
225 values = palloc(6 *
sizeof(Datum));
226 nulls = palloc(6 *
sizeof(
bool));
230 for (i = 0; i < 6; ++i) {
235 values[0] = Int32GetDatum(funcctx->call_cntr + 1);
236 values[1] = Int32GetDatum(result_tuples[funcctx->call_cntr].
seq);
237 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
node);
238 values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
239 values[4] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
240 values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].
agg_cost);
242 tuple = heap_form_tuple(tuple_desc, values, nulls);
243 result = HeapTupleGetDatum(tuple);
244 SRF_RETURN_NEXT(funcctx, result);
247 SRF_RETURN_DONE(funcctx);