53 size_t *result_count) {
56 (*result_tuples) = NULL;
60 size_t total_edges = 0;
64 if (total_edges == 0) {
69 clock_t start_t = clock();
71 char *notice_msg = NULL;
83 time_msg(
" processing pgr_connectedComponents", start_t, clock());
86 if (*result_tuples) pfree(*result_tuples);
90 if (edges) pfree(edges);
91 if (log_msg) pfree(log_msg);
92 if (notice_msg) pfree(notice_msg);
93 if (err_msg) pfree(err_msg);
99 FuncCallContext *funcctx;
100 TupleDesc tuple_desc;
103 size_t result_count = 0;
105 if (SRF_IS_FIRSTCALL()) {
106 MemoryContext oldcontext;
107 funcctx = SRF_FIRSTCALL_INIT();
108 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
112 text_to_cstring(PG_GETARG_TEXT_P(0)),
117 #if PGSQL_VERSION > 94
118 funcctx->max_calls = (uint32_t)result_count;
120 funcctx->max_calls = (uint32_t)result_count;
122 funcctx->user_fctx = result_tuples;
123 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
124 != TYPEFUNC_COMPOSITE) {
126 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
127 errmsg(
"function returning record called in context "
128 "that cannot accept type record")));
131 funcctx->tuple_desc = tuple_desc;
132 MemoryContextSwitchTo(oldcontext);
135 funcctx = SRF_PERCALL_SETUP();
136 tuple_desc = funcctx->tuple_desc;
139 if (funcctx->call_cntr < funcctx->max_calls) {
147 values = palloc(numb *
sizeof(Datum));
148 nulls = palloc(numb *
sizeof(
bool));
151 for (i = 0; i < numb; ++i) {
155 values[0] = Int64GetDatum(funcctx->call_cntr + 1);
156 values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].
component);
157 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
identifier);
159 tuple = heap_form_tuple(tuple_desc, values, nulls);
160 result = HeapTupleGetDatum(tuple);
161 SRF_RETURN_NEXT(funcctx, result);
163 SRF_RETURN_DONE(funcctx);