27 #include "utils/array.h"
50 size_t *result_count) {
53 size_t size_start_vidsArr = 0;
57 size_t total_tuples = 0;
60 if (total_tuples == 0) {
65 clock_t start_t = clock();
67 char* notice_msg = NULL;
71 start_vidsArr, size_start_vidsArr,
75 result_tuples, result_count,
80 time_msg(
"processing pgr_drivingDistance()",
83 if (err_msg && (*result_tuples)) {
84 pfree(*result_tuples);
85 (*result_tuples) = NULL;
91 if (log_msg) pfree(log_msg);
92 if (notice_msg) pfree(notice_msg);
93 if (err_msg) pfree(err_msg);
94 if (edges) pfree(edges);
95 if (start_vidsArr) pfree(start_vidsArr);
103 FuncCallContext *funcctx;
104 TupleDesc tuple_desc;
108 size_t result_count = 0;
111 if (SRF_IS_FIRSTCALL()) {
112 MemoryContext oldcontext;
114 funcctx = SRF_FIRSTCALL_INIT();
115 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
119 PGR_DBG(
"Calling driving_many_to_dist_driver");
121 text_to_cstring(PG_GETARG_TEXT_P(0)),
122 PG_GETARG_ARRAYTYPE_P(1),
126 &result_tuples, &result_count);
131 #if PGSQL_VERSION > 95
132 funcctx->max_calls = result_count;
134 funcctx->max_calls = (uint32_t)result_count;
136 funcctx->user_fctx = result_tuples;
137 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
138 != TYPEFUNC_COMPOSITE)
140 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
141 errmsg(
"function returning record called in context "
142 "that cannot accept type record")));
144 funcctx->tuple_desc = tuple_desc;
146 MemoryContextSwitchTo(oldcontext);
149 funcctx = SRF_PERCALL_SETUP();
151 tuple_desc = funcctx->tuple_desc;
154 if (funcctx->call_cntr < funcctx->max_calls) {
162 values = palloc(numb *
sizeof(Datum));
163 nulls = palloc(numb *
sizeof(
bool));
166 for (i = 0; i < numb; ++i) {
169 values[0] = Int32GetDatum(funcctx->call_cntr + 1);
170 values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].
start_id);
171 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
node);
172 values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
173 values[4] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
174 values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].
agg_cost);
177 tuple = heap_form_tuple(tuple_desc, values, nulls);
178 result = HeapTupleGetDatum(tuple);
183 SRF_RETURN_NEXT(funcctx, result);
185 SRF_RETURN_DONE(funcctx);