38 #include "utils/array.h"
66 size_t *result_count) {
69 int64_t* start_vidsArr = NULL;
70 size_t size_start_vidsArr = 0;
72 int64_t* end_vidsArr = NULL;
73 size_t size_end_vidsArr = 0;
76 size_t total_edges = 0;
79 start_vidsArr = (int64_t*)
81 end_vidsArr = (int64_t*)
85 end_vidsArr = (int64_t*)
87 start_vidsArr = (int64_t*)
91 if (total_edges == 0) {
92 if (end_vidsArr) pfree(end_vidsArr);
93 if (start_vidsArr) pfree(start_vidsArr);
98 clock_t start_t = clock();
100 char* notice_msg = NULL;
101 char* err_msg = NULL;
104 start_vidsArr, size_start_vidsArr,
105 end_vidsArr, size_end_vidsArr,
122 time_msg(
"processing pgr_dijkstraNearCost", start_t, clock());
124 time_msg(
"processing pgr_dijkstraCost", start_t, clock());
128 time_msg(
"processing pgr_dijkstraNear", start_t, clock());
130 time_msg(
"processing pgr_dijkstra", start_t, clock());
135 if (err_msg && (*result_tuples)) {
136 pfree(*result_tuples);
137 (*result_tuples) = NULL;
143 if (log_msg) pfree(log_msg);
144 if (notice_msg) pfree(notice_msg);
145 if (err_msg) pfree(err_msg);
146 if (edges) pfree(edges);
147 if (start_vidsArr) pfree(start_vidsArr);
148 if (end_vidsArr) pfree(end_vidsArr);
158 char* combinations_sql,
164 size_t *result_count) {
168 size_t total_edges = 0;
171 size_t total_combinations = 0;
175 if (total_edges == 0) {
180 if (total_combinations == 0) {
181 if (edges) pfree(edges);
186 clock_t start_t = clock();
187 char* log_msg = NULL;
188 char* notice_msg = NULL;
189 char* err_msg = NULL;
192 combinations, total_combinations,
208 time_msg(
"Processing pgr_dijkstraNearCost", start_t, clock());
210 time_msg(
"Processing pgr_dijkstraCost", start_t, clock());
214 time_msg(
"Processing pgr_dijkstraNear", start_t, clock());
216 time_msg(
"Processing pgr_dijkstra", start_t, clock());
220 if (err_msg && (*result_tuples)) {
221 pfree(*result_tuples);
222 (*result_tuples) = NULL;
228 if (log_msg) pfree(log_msg);
229 if (notice_msg) pfree(notice_msg);
230 if (err_msg) pfree(err_msg);
231 if (edges) pfree(edges);
232 if (combinations) pfree(combinations);
241 FuncCallContext *funcctx;
242 TupleDesc tuple_desc;
246 size_t result_count = 0;
249 if (SRF_IS_FIRSTCALL()) {
250 MemoryContext oldcontext;
251 funcctx = SRF_FIRSTCALL_INIT();
252 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
253 if (PG_NARGS() == 7) {
264 text_to_cstring(PG_GETARG_TEXT_P(0)),
265 PG_GETARG_ARRAYTYPE_P(1),
266 PG_GETARG_ARRAYTYPE_P(2),
276 }
else if (PG_NARGS() == 5) {
285 text_to_cstring(PG_GETARG_TEXT_P(0)),
286 text_to_cstring(PG_GETARG_TEXT_P(1)),
293 }
else if (PG_NARGS() == 8) {
295 text_to_cstring(PG_GETARG_TEXT_P(0)),
296 PG_GETARG_ARRAYTYPE_P(1),
297 PG_GETARG_ARRAYTYPE_P(2),
316 text_to_cstring(PG_GETARG_TEXT_P(0)),
317 text_to_cstring(PG_GETARG_TEXT_P(1)),
327 #if PGSQL_VERSION > 95
328 funcctx->max_calls = result_count;
330 funcctx->max_calls = (uint32_t)result_count;
333 funcctx->user_fctx = result_tuples;
334 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
335 != TYPEFUNC_COMPOSITE) {
337 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
338 errmsg(
"function returning record called in context "
339 "that cannot accept type record")));
342 funcctx->tuple_desc = tuple_desc;
343 MemoryContextSwitchTo(oldcontext);
346 funcctx = SRF_PERCALL_SETUP();
347 tuple_desc = funcctx->tuple_desc;
350 if (funcctx->call_cntr < funcctx->max_calls) {
355 size_t call_cntr = funcctx->call_cntr;
368 values = palloc(numb *
sizeof(Datum));
369 nulls = palloc(numb *
sizeof(
bool));
372 for (i = 0; i < numb; ++i) {
376 values[0] = Int32GetDatum(call_cntr + 1);
377 values[1] = Int32GetDatum(result_tuples[call_cntr].seq);
378 values[2] = Int64GetDatum(result_tuples[call_cntr].start_id);
379 values[3] = Int64GetDatum(result_tuples[call_cntr].end_id);
380 values[4] = Int64GetDatum(result_tuples[call_cntr].node);
381 values[5] = Int64GetDatum(result_tuples[call_cntr].
edge);
382 values[6] = Float8GetDatum(result_tuples[call_cntr].cost);
383 values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost);
386 tuple = heap_form_tuple(tuple_desc, values, nulls);
387 result = HeapTupleGetDatum(tuple);
388 SRF_RETURN_NEXT(funcctx, result);
390 SRF_RETURN_DONE(funcctx);