32 #include "utils/array.h"
54 char* combinations_sql,
66 size_t *result_count) {
71 size_t size_start_pidsArr = 0;
72 int64_t* start_pidsArr = NULL;
74 size_t size_end_pidsArr = 0;
75 int64_t* end_pidsArr = NULL;
78 size_t total_combinations = 0;
81 size_t total_points = 0;
86 for (i = 0; i< total_points; i++) {
90 char *edges_of_points_query = NULL;
91 char *edges_no_points_query = NULL;
93 edges_sql, points_sql,
94 &edges_of_points_query,
95 &edges_no_points_query);
99 size_t total_edges_of_points = 0;
102 size_t total_edges = 0;
106 edges_of_points_query,
108 &total_edges_of_points);
111 if (starts && ends) {
112 start_pidsArr = (int64_t*)
114 end_pidsArr = (int64_t*)
116 }
else if (combinations_sql) {
121 edges_of_points_query,
123 &total_edges_of_points);
126 end_pidsArr = (int64_t*)
128 start_pidsArr = (int64_t*)
133 pfree(edges_of_points_query);
134 pfree(edges_no_points_query);
135 edges_of_points_query = NULL;
136 edges_no_points_query = NULL;
138 if ((total_edges + total_edges_of_points) == 0) {
143 clock_t start_t = clock();
144 char* log_msg = NULL;
145 char* notice_msg = NULL;
146 char* err_msg = NULL;
150 points, total_points,
151 edges_of_points, total_edges_of_points,
153 combinations, total_combinations,
155 start_pidsArr, size_start_pidsArr,
156 end_pidsArr, size_end_pidsArr,
164 result_tuples, result_count,
170 time_msg(
"processing pgr_withPointsCost", start_t, clock());
172 time_msg(
"processing pgr_withPoints", start_t, clock());
175 if (err_msg && (*result_tuples)) {
176 pfree(*result_tuples);
178 (*result_tuples) = NULL;
184 if (log_msg) pfree(log_msg);
185 if (notice_msg) pfree(notice_msg);
186 if (err_msg) pfree(err_msg);
187 if (edges) pfree(edges);
188 if (points) pfree(points);
189 if (edges_of_points) pfree(edges_of_points);
190 if (start_pidsArr) pfree(start_pidsArr);
191 if (end_pidsArr) pfree(end_pidsArr);
201 FuncCallContext *funcctx;
202 TupleDesc tuple_desc;
206 size_t result_count = 0;
209 if (SRF_IS_FIRSTCALL()) {
210 MemoryContext oldcontext;
211 funcctx = SRF_FIRSTCALL_INIT();
212 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
215 if (PG_NARGS() == 9) {
221 text_to_cstring(PG_GETARG_TEXT_P(0)),
222 text_to_cstring(PG_GETARG_TEXT_P(1)),
224 PG_GETARG_ARRAYTYPE_P(2),
225 PG_GETARG_ARRAYTYPE_P(3),
227 text_to_cstring(PG_GETARG_TEXT_P(5)),
234 }
else if (PG_NARGS() == 7) {
240 text_to_cstring(PG_GETARG_TEXT_P(0)),
241 text_to_cstring(PG_GETARG_TEXT_P(1)),
242 text_to_cstring(PG_GETARG_TEXT_P(2)),
246 text_to_cstring(PG_GETARG_TEXT_P(4)),
256 #if PGSQL_VERSION > 95
257 funcctx->max_calls = result_count;
259 funcctx->max_calls = (uint32_t)result_count;
261 funcctx->user_fctx = result_tuples;
262 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
263 != TYPEFUNC_COMPOSITE)
265 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
266 errmsg(
"function returning record called in context "
267 "that cannot accept type record")));
269 funcctx->tuple_desc = tuple_desc;
270 MemoryContextSwitchTo(oldcontext);
273 funcctx = SRF_PERCALL_SETUP();
274 tuple_desc = funcctx->tuple_desc;
277 if (funcctx->call_cntr < funcctx->max_calls) {
292 values = palloc(8 *
sizeof(Datum));
293 nulls = palloc(8 *
sizeof(
bool));
296 for (i = 0; i < 8; ++i) {
301 values[0] = Int32GetDatum(funcctx->call_cntr + 1);
302 values[1] = Int32GetDatum(result_tuples[funcctx->call_cntr].
seq);
303 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
start_id);
304 values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].
end_id);
305 values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].
node);
306 values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
307 values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
308 values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].
agg_cost);
311 tuple = heap_form_tuple(tuple_desc, values, nulls);
312 result = HeapTupleGetDatum(tuple);
313 SRF_RETURN_NEXT(funcctx, result);
315 SRF_RETURN_DONE(funcctx);