32 #include "utils/array.h"
63 size_t *result_count) {
68 size_t k = (size_t)p_k;
70 driving_side[0] = (char) tolower(driving_side[0]);
71 PGR_DBG(
"driving side:%c", driving_side[0]);
72 if (!((driving_side[0] ==
'r')
73 || (driving_side[0] ==
'l'))) {
74 driving_side[0] =
'b';
80 size_t total_points = 0;
83 char *edges_of_points_query = NULL;
84 char *edges_no_points_query = NULL;
86 edges_sql, points_sql,
87 &edges_of_points_query,
88 &edges_no_points_query);
92 size_t total_edges_of_points = 0;
95 &total_edges_of_points);
98 size_t total_edges = 0;
101 PGR_DBG(
"freeing allocated memory not used anymore");
102 pfree(edges_of_points_query);
103 pfree(edges_no_points_query);
105 if ((total_edges + total_edges_of_points) == 0) {
108 (*result_tuples) = NULL;
113 PGR_DBG(
"Starting processing");
114 clock_t start_t = clock();
116 char *log_msg = NULL;
117 char *notice_msg = NULL;
118 char *err_msg = NULL;
125 total_edges_of_points,
141 time_msg(
" processing withPointsKSP", start_t, clock());
143 if (err_msg && (*result_tuples)) {
144 pfree(*result_tuples);
145 (*result_tuples) = NULL;
151 if (log_msg) pfree(log_msg);
152 if (notice_msg) pfree(notice_msg);
153 if (err_msg) pfree(err_msg);
156 pfree(edges_of_points);
166 FuncCallContext *funcctx;
167 TupleDesc tuple_desc;
170 size_t result_count = 0;
172 if (SRF_IS_FIRSTCALL()) {
173 MemoryContext oldcontext;
174 funcctx = SRF_FIRSTCALL_INIT();
175 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
193 PGR_DBG(
"initial driving side:%s",
194 text_to_cstring(PG_GETARG_TEXT_P(7)));
196 text_to_cstring(PG_GETARG_TEXT_P(0)),
197 text_to_cstring(PG_GETARG_TEXT_P(1)),
203 text_to_cstring(PG_GETARG_TEXT_P(7)),
209 #if PGSQL_VERSION > 95
210 funcctx->max_calls = result_count;
212 funcctx->max_calls = (uint32_t)result_count;
214 funcctx->user_fctx = result_tuples;
215 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
216 != TYPEFUNC_COMPOSITE)
218 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
219 errmsg(
"function returning record called in context "
220 "that cannot accept type record")));
222 funcctx->tuple_desc = tuple_desc;
223 MemoryContextSwitchTo(oldcontext);
226 funcctx = SRF_PERCALL_SETUP();
227 tuple_desc = funcctx->tuple_desc;
230 if (funcctx->call_cntr < funcctx->max_calls) {
236 values = palloc(7 *
sizeof(Datum));
237 nulls = palloc(7 *
sizeof(
bool));
240 for (i = 0; i < 7; ++i) {
252 values[0] = Int32GetDatum(funcctx->call_cntr + 1);
253 values[1] = Int32GetDatum((
int)
254 (result_tuples[funcctx->call_cntr].
start_id + 1));
255 values[2] = Int32GetDatum(result_tuples[funcctx->call_cntr].
seq);
256 values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].
node);
257 values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
258 values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
259 values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].
agg_cost);
261 tuple = heap_form_tuple(tuple_desc, values, nulls);
262 result = HeapTupleGetDatum(tuple);
263 SRF_RETURN_NEXT(funcctx, result);
265 SRF_RETURN_DONE(funcctx);