28 #include "utils/array.h"
45 PGDLLEXPORT Datum
_trsp(PG_FUNCTION_ARGS);
52 char* restrictions_sql,
60 size_t *result_count) {
64 size_t total_edges = 0;
68 size_t total_restrictions = 0;
71 size_t size_start_vidsArr = 0;
72 int64_t* start_vidsArr = (int64_t*)
75 size_t size_end_vidsArr = 0;
76 int64_t* end_vidsArr = (int64_t*)
80 clock_t start_t = clock();
82 char* notice_msg = NULL;
92 start_vidsArr, size_start_vidsArr,
93 end_vidsArr, size_end_vidsArr,
102 time_msg(
"processing _pgr_trsp", start_t, clock());
104 if (err_msg && (*result_tuples)) {
105 pfree(*result_tuples);
106 (*result_tuples) = NULL;
119 FuncCallContext *funcctx;
120 TupleDesc tuple_desc;
122 size_t result_count = 0;
126 if (SRF_IS_FIRSTCALL()) {
127 MemoryContext oldcontext;
128 funcctx = SRF_FIRSTCALL_INIT();
129 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
131 PGR_DBG(
"Calling compute_trsp");
133 text_to_cstring(PG_GETARG_TEXT_P(0)),
134 text_to_cstring(PG_GETARG_TEXT_P(1)),
135 PG_GETARG_ARRAYTYPE_P(2),
136 PG_GETARG_ARRAYTYPE_P(3),
138 &result_tuples, &result_count);
142 #if PGSQL_VERSION > 95
143 funcctx->max_calls = result_count;
145 funcctx->max_calls = (uint32_t)result_count;
148 funcctx->user_fctx = result_tuples;
149 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
150 != TYPEFUNC_COMPOSITE) {
152 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
153 errmsg(
"function returning record called in context "
154 "that cannot accept type record")));
157 funcctx->tuple_desc = tuple_desc;
158 MemoryContextSwitchTo(oldcontext);
161 funcctx = SRF_PERCALL_SETUP();
163 tuple_desc = funcctx->tuple_desc;
166 if (funcctx->call_cntr < funcctx->max_calls) {
172 size_t call_cntr = funcctx->call_cntr;
176 values = palloc(numb *
sizeof(Datum));
177 nulls = palloc(numb *
sizeof(
bool));
180 for (i = 0; i < numb; ++i) {
184 values[0] = Int32GetDatum(call_cntr + 1);
185 values[1] = Int32GetDatum(result_tuples[call_cntr].seq);
186 values[2] = Int64GetDatum(result_tuples[call_cntr].start_id);
187 values[3] = Int64GetDatum(result_tuples[call_cntr].end_id);
188 values[4] = Int64GetDatum(result_tuples[call_cntr].node);
189 values[5] = Int64GetDatum(result_tuples[call_cntr].
edge);
190 values[6] = Float8GetDatum(result_tuples[call_cntr].cost);
191 values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost);
193 tuple = heap_form_tuple(tuple_desc, values, nulls);
195 result = HeapTupleGetDatum(tuple);
200 SRF_RETURN_NEXT(funcctx, result);
202 SRF_RETURN_DONE(funcctx);