34 #include "utils/array.h"
54 size_t *result_count) {
58 size_t total_edges = 0;
62 clock_t start_t = clock();
64 char* notice_msg = NULL;
74 time_msg(
"processing pgr_topologicalSort", start_t, clock());
77 if (err_msg && (*result_tuples)) {
78 pfree(*result_tuples);
79 (*result_tuples) = NULL;
85 if (log_msg) pfree(log_msg);
86 if (notice_msg) pfree(notice_msg);
87 if (err_msg) pfree(err_msg);
88 if (edges) pfree(edges);
94 FuncCallContext *funcctx;
99 size_t result_count = 0;
102 if (SRF_IS_FIRSTCALL()) {
103 MemoryContext oldcontext;
104 funcctx = SRF_FIRSTCALL_INIT();
105 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
113 text_to_cstring(PG_GETARG_TEXT_P(0)),
119 #if PGSQL_VERSION > 95
120 funcctx->max_calls = result_count;
122 funcctx->max_calls = (uint32_t)result_count;
125 funcctx->user_fctx = result_tuples;
126 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
127 != TYPEFUNC_COMPOSITE) {
129 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
130 errmsg(
"function returning record called in context "
131 "that cannot accept type record")));
134 funcctx->tuple_desc = tuple_desc;
135 MemoryContextSwitchTo(oldcontext);
138 funcctx = SRF_PERCALL_SETUP();
139 tuple_desc = funcctx->tuple_desc;
142 if (funcctx->call_cntr < funcctx->max_calls) {
147 size_t call_cntr = funcctx->call_cntr;
154 values = palloc(numb *
sizeof(Datum));
155 nulls = palloc(numb *
sizeof(
bool));
158 for (i = 0; i < numb; ++i) {
162 values[0] = Int32GetDatum(call_cntr + 1);
163 values[1] = Int64GetDatum(result_tuples[call_cntr].sorted_v);
166 tuple = heap_form_tuple(tuple_desc, values, nulls);
167 result = HeapTupleGetDatum(tuple);
168 SRF_RETURN_NEXT(funcctx, result);
170 SRF_RETURN_DONE(funcctx);