27 #include "utils/array.h"
57 size_t *result_count) {
59 PGR_DBG(
"estimated driving side:%c", driving_side[0]);
63 size_t total_starts = 0;
65 PGR_DBG(
"sourcesArr size %ld ", total_starts);
68 size_t total_points = 0;
71 char *edges_of_points_query = NULL;
72 char *edges_no_points_query = NULL;
74 edges_sql, points_sql,
75 &edges_of_points_query,
76 &edges_no_points_query);
80 size_t total_edges_of_points = 0;
82 edges_of_points_query, &edges_of_points, &total_edges_of_points);
85 size_t total_edges = 0;
88 PGR_DBG(
"freeing allocated memory not used anymore");
89 pfree(edges_of_points_query);
90 pfree(edges_no_points_query);
92 if ((total_edges + total_edges_of_points) == 0) {
93 if (edges) pfree(edges);
94 if (edges_of_points) pfree(edges_of_points);
95 if (points) pfree(points);
101 clock_t start_t = clock();
102 char* log_msg = NULL;
103 char* notice_msg = NULL;
104 char* err_msg = NULL;
107 points, total_points,
108 edges_of_points, total_edges_of_points,
109 start_pidsArr, total_starts,
122 time_msg(
" processing withPointsDD many starts", start_t, clock());
124 if (err_msg && (*result_tuples)) {
125 pfree(*result_tuples);
127 (*result_tuples) = NULL;
132 if (log_msg) pfree(log_msg);
133 if (notice_msg) pfree(notice_msg);
134 if (err_msg) pfree(err_msg);
135 if (edges) pfree(edges);
136 if (edges_of_points) pfree(edges_of_points);
137 if (points) pfree(points);
138 if (start_pidsArr) pfree(start_pidsArr);
146 FuncCallContext *funcctx;
147 TupleDesc tuple_desc;
151 size_t result_count = 0;
155 if (SRF_IS_FIRSTCALL()) {
156 MemoryContext oldcontext;
157 funcctx = SRF_FIRSTCALL_INIT();
158 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
174 PGR_DBG(
"Calling driving_many_to_dist_driver");
176 text_to_cstring(PG_GETARG_TEXT_P(0)),
177 text_to_cstring(PG_GETARG_TEXT_P(1)),
178 PG_GETARG_ARRAYTYPE_P(2),
182 text_to_cstring(PG_GETARG_TEXT_P(5)),
185 &result_tuples, &result_count);
189 #if PGSQL_VERSION > 95
190 funcctx->max_calls = result_count;
192 funcctx->max_calls = (uint32_t)result_count;
194 funcctx->user_fctx = result_tuples;
195 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
196 != TYPEFUNC_COMPOSITE)
198 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
199 errmsg(
"function returning record called in context "
200 "that cannot accept type record")));
202 funcctx->tuple_desc = tuple_desc;
204 MemoryContextSwitchTo(oldcontext);
207 funcctx = SRF_PERCALL_SETUP();
209 tuple_desc = funcctx->tuple_desc;
212 if (funcctx->call_cntr < funcctx->max_calls) {
220 values = palloc(numb *
sizeof(Datum));
221 nulls = palloc(numb *
sizeof(
bool));
224 for (i = 0; i < numb; ++i) {
228 values[0] = Int32GetDatum(funcctx->call_cntr + 1);
229 values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].
start_id);
230 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
node);
231 values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
232 values[4] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
233 values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].
agg_cost);
237 tuple = heap_form_tuple(tuple_desc, values, nulls);
238 result = HeapTupleGetDatum(tuple);
243 SRF_RETURN_NEXT(funcctx, result);
245 SRF_RETURN_DONE(funcctx);