33 #include "utils/array.h"
50 char *combinations_sql,
56 size_t *result_count) {
59 int64_t *source_vertices = NULL;
60 size_t size_source_verticesArr = 0;
62 int64_t *sink_vertices = NULL;
63 size_t size_sink_verticesArr = 0;
67 size_t total_edges = 0;
70 size_t total_combinations = 0;
73 source_vertices = (int64_t*)
75 sink_vertices = (int64_t*)
77 }
else if (combinations_sql) {
79 if (total_combinations == 0) {
89 if (total_edges == 0) {
90 if (source_vertices) pfree(source_vertices);
91 if (sink_vertices) pfree(sink_vertices);
98 clock_t start_t = clock();
100 char* notice_msg = NULL;
101 char* err_msg = NULL;
105 combinations, total_combinations,
106 source_vertices, size_source_verticesArr,
107 sink_vertices, size_sink_verticesArr,
110 result_tuples, result_count,
116 time_msg(
"pgr_edgeDisjointPaths(many to many)", start_t, clock());
118 if (edges) pfree(edges);
119 if (source_vertices) pfree(source_vertices);
120 if (sink_vertices) pfree(sink_vertices);
122 if (err_msg && (*result_tuples)) {
123 pfree(*result_tuples);
124 (*result_tuples) = NULL;
130 if (log_msg) pfree(log_msg);
131 if (notice_msg) pfree(notice_msg);
132 if (err_msg) pfree(err_msg);
139 FuncCallContext *funcctx;
140 TupleDesc tuple_desc;
143 size_t result_count = 0;
145 if (SRF_IS_FIRSTCALL()) {
146 MemoryContext oldcontext;
147 funcctx = SRF_FIRSTCALL_INIT();
148 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
151 if (PG_NARGS() == 4) {
156 text_to_cstring(PG_GETARG_TEXT_P(0)),
158 PG_GETARG_ARRAYTYPE_P(1),
159 PG_GETARG_ARRAYTYPE_P(2),
164 }
else if (PG_NARGS() == 3) {
169 text_to_cstring(PG_GETARG_TEXT_P(0)),
170 text_to_cstring(PG_GETARG_TEXT_P(1)),
179 #if PGSQL_VERSION > 95
180 funcctx->max_calls = result_count;
182 funcctx->max_calls = (uint32_t)result_count;
184 funcctx->user_fctx = result_tuples;
185 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
186 != TYPEFUNC_COMPOSITE) {
188 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
189 errmsg(
"function returning record called in context "
190 "that cannot accept type record")));
193 funcctx->tuple_desc = tuple_desc;
194 MemoryContextSwitchTo(oldcontext);
197 funcctx = SRF_PERCALL_SETUP();
198 tuple_desc = funcctx->tuple_desc;
201 if (funcctx->call_cntr < funcctx->max_calls) {
208 values = palloc(9 *
sizeof(Datum));
209 nulls = palloc(9 *
sizeof(
bool));
212 for (i = 0; i < 9; ++i) {
216 values[0] = Int32GetDatum(funcctx->call_cntr + 1);
217 values[1] = Int32GetDatum(
218 result_tuples[funcctx->call_cntr].
start_id + 1);
219 values[2] = Int32GetDatum(result_tuples[funcctx->call_cntr].
seq);
220 values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].
start_id);
221 values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].
end_id);
222 values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].
node);
223 values[6] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
224 values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
225 values[8] = Float8GetDatum(result_tuples[funcctx->call_cntr].
agg_cost);
227 tuple = heap_form_tuple(tuple_desc, values, nulls);
228 result = HeapTupleGetDatum(tuple);
229 SRF_RETURN_NEXT(funcctx, result);
231 SRF_RETURN_DONE(funcctx);