50 size_t *result_count) {
56 (*result_tuples) = NULL;
61 size_t total_edges = 0;
64 PGR_DBG(
"Total %ld edges in query:", total_edges);
66 if (total_edges == 0) {
73 clock_t start_t = clock();
75 char *notice_msg = NULL;
88 time_msg(
" processing pgr_randomSpanningTree", start_t, clock());
89 PGR_DBG(
"Returning %ld tuples", *result_count);
92 if (*result_tuples) pfree(*result_tuples);
96 if (edges) pfree(edges);
97 if (log_msg) pfree(log_msg);
98 if (notice_msg) pfree(notice_msg);
99 if (err_msg) pfree(err_msg);
107 FuncCallContext *funcctx;
108 TupleDesc tuple_desc;
111 size_t result_count = 0;
113 if (SRF_IS_FIRSTCALL()) {
114 MemoryContext oldcontext;
115 funcctx = SRF_FIRSTCALL_INIT();
116 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
121 text_to_cstring(PG_GETARG_TEXT_P(0)),
127 #if PGSQL_VERSION > 94
128 funcctx->max_calls = (uint32_t)result_count;
130 funcctx->max_calls = (uint32_t)result_count;
132 funcctx->user_fctx = result_tuples;
133 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
134 != TYPEFUNC_COMPOSITE) {
136 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
137 errmsg(
"function returning record called in context "
138 "that cannot accept type record")));
141 funcctx->tuple_desc = tuple_desc;
142 MemoryContextSwitchTo(oldcontext);
145 funcctx = SRF_PERCALL_SETUP();
146 tuple_desc = funcctx->tuple_desc;
149 if (funcctx->call_cntr < funcctx->max_calls) {
155 values = palloc(5 *
sizeof(Datum));
156 nulls = palloc(5 *
sizeof(
bool));
160 for (i = 0; i < 5; ++i) {
165 values[0] = Int64GetDatum(funcctx->call_cntr + 1);
167 Int64GetDatum(result_tuples[funcctx->call_cntr].
root_vertex);
168 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
169 values[3] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
170 values[4] = Float8GetDatum(result_tuples[funcctx->call_cntr].
tree_cost);
173 tuple = heap_form_tuple(tuple_desc, values, nulls);
174 result = HeapTupleGetDatum(tuple);
175 SRF_RETURN_NEXT(funcctx, result);
179 SRF_RETURN_DONE(funcctx);