32 #include "utils/array.h"
55 char* combinations_sql,
64 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_combinations = 0;
79 start_vidsArr = (int64_t*)
81 end_vidsArr = (int64_t*)
83 }
else if (combinations_sql) {
88 size_t total_edges = 0;
91 PGR_DBG(
"Total %ld edges in query:", total_edges);
93 if (total_edges == 0) {
96 (*result_tuples) = NULL;
101 PGR_DBG(
"Starting processing");
102 char* log_msg = NULL;
103 char* notice_msg = NULL;
104 char* err_msg = NULL;
105 clock_t start_t = clock();
108 combinations, total_combinations,
109 start_vidsArr, size_start_vidsArr,
110 end_vidsArr, size_end_vidsArr,
125 time_msg(
"pgr_bdAstarCost()", start_t, clock());
127 time_msg(
"pgr_bdAstar()", start_t, clock());
130 if (err_msg && (*result_tuples)) {
131 pfree(*result_tuples);
133 (*result_tuples) = NULL;
138 if (log_msg) pfree(log_msg);
139 if (notice_msg) pfree(notice_msg);
140 if (err_msg) pfree(err_msg);
141 if (edges) pfree(edges);
148 FuncCallContext *funcctx;
149 TupleDesc tuple_desc;
152 size_t result_count = 0;
154 if (SRF_IS_FIRSTCALL()) {
155 MemoryContext oldcontext;
156 funcctx = SRF_FIRSTCALL_INIT();
157 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
160 if (PG_NARGS() == 8) {
165 text_to_cstring(PG_GETARG_TEXT_P(0)),
167 PG_GETARG_ARRAYTYPE_P(1),
168 PG_GETARG_ARRAYTYPE_P(2),
178 }
else if (PG_NARGS() == 7) {
183 text_to_cstring(PG_GETARG_TEXT_P(0)),
184 text_to_cstring(PG_GETARG_TEXT_P(1)),
199 #if PGSQL_VERSION > 95
200 funcctx->max_calls = result_count;
202 funcctx->max_calls = (uint32_t)result_count;
204 funcctx->user_fctx = result_tuples;
205 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
206 != TYPEFUNC_COMPOSITE)
208 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
209 errmsg(
"function returning record called in context "
210 "that cannot accept type record")));
212 funcctx->tuple_desc = tuple_desc;
213 MemoryContextSwitchTo(oldcontext);
216 funcctx = SRF_PERCALL_SETUP();
217 tuple_desc = funcctx->tuple_desc;
220 if (funcctx->call_cntr < funcctx->max_calls) {
225 size_t call_cntr = funcctx->call_cntr;
238 values = palloc(numb *
sizeof(Datum));
239 nulls = palloc(numb *
sizeof(
bool));
243 for (i = 0; i < numb; ++i) {
247 values[0] = Int32GetDatum(call_cntr + 1);
248 values[1] = Int32GetDatum(result_tuples[call_cntr].seq);
249 values[2] = Int64GetDatum(result_tuples[call_cntr].start_id);
250 values[3] = Int64GetDatum(result_tuples[call_cntr].end_id);
251 values[4] = Int64GetDatum(result_tuples[call_cntr].node);
252 values[5] = Int64GetDatum(result_tuples[call_cntr].
edge);
253 values[6] = Float8GetDatum(result_tuples[call_cntr].cost);
254 values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost);
257 tuple = heap_form_tuple(tuple_desc, values, nulls);
258 result = HeapTupleGetDatum(tuple);
259 SRF_RETURN_NEXT(funcctx, result);
261 SRF_RETURN_DONE(funcctx);