48 #include "utils/array.h"
75 char* combinations_sql,
80 size_t *result_count) {
86 int64_t *sourceVertices = NULL;
87 size_t sizeSourceVerticesArr = 0;
89 int64_t *sinkVertices = NULL;
90 size_t sizeSinkVerticesArr = 0;
94 size_t total_edges = 0;
97 size_t total_combinations = 0;
100 sourceVertices = (int64_t*)
102 sinkVertices = (int64_t*)
104 }
else if (combinations_sql) {
106 if (total_combinations == 0) {
115 PGR_DBG(
"Total %ld edges in query:", total_edges);
117 if (total_edges == 0) {
119 pfree(sourceVertices);
127 PGR_DBG(
"Starting processing");
128 clock_t start_t = clock();
129 char *log_msg = NULL;
130 char *notice_msg = NULL;
131 char *err_msg = NULL;
135 combinations, total_combinations,
136 sourceVertices, sizeSourceVerticesArr,
137 sinkVertices, sizeSinkVerticesArr,
140 result_tuples, result_count,
147 time_msg(
" processing pgr_minCostMaxFlow_Cost", start_t, clock());
149 time_msg(
" processing pgr_minCostMaxFlow", start_t, clock());
152 PGR_DBG(
"Returning %ld tuples", *result_count);
157 pfree(sourceVertices);
161 if (err_msg && (*result_tuples)) {
162 pfree(*result_tuples);
163 (*result_tuples) = NULL;
169 if (log_msg) pfree(log_msg);
170 if (notice_msg) pfree(notice_msg);
171 if (err_msg) pfree(err_msg);
179 FuncCallContext *funcctx;
180 TupleDesc tuple_desc;
186 size_t result_count = 0;
190 if (SRF_IS_FIRSTCALL()) {
191 MemoryContext oldcontext;
192 funcctx = SRF_FIRSTCALL_INIT();
193 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
207 if (PG_NARGS() == 4) {
212 text_to_cstring(PG_GETARG_TEXT_P(0)),
214 PG_GETARG_ARRAYTYPE_P(1),
215 PG_GETARG_ARRAYTYPE_P(2),
220 }
else if (PG_NARGS() == 3) {
225 text_to_cstring(PG_GETARG_TEXT_P(0)),
226 text_to_cstring(PG_GETARG_TEXT_P(1)),
237 #if PGSQL_VERSION > 94
238 funcctx->max_calls = (uint32_t)result_count;
240 funcctx->max_calls = (uint32_t)result_count;
242 funcctx->user_fctx = result_tuples;
243 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
244 != TYPEFUNC_COMPOSITE) {
246 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
247 errmsg(
"function returning record called in context "
248 "that cannot accept type record")));
251 funcctx->tuple_desc = tuple_desc;
252 MemoryContextSwitchTo(oldcontext);
255 funcctx = SRF_PERCALL_SETUP();
256 tuple_desc = funcctx->tuple_desc;
257 result_tuples = (
pgr_flow_t*) funcctx->user_fctx;
259 if (funcctx->call_cntr < funcctx->max_calls) {
270 values = palloc(8 *
sizeof(Datum));
271 nulls = palloc(8 *
sizeof(
bool));
275 for (i = 0; i < 8; ++i) {
280 values[0] = Int32GetDatum(funcctx->call_cntr + 1);
281 values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
282 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
source);
283 values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].
target);
284 values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].
flow);
285 values[5] = Int64GetDatum(
287 values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
288 values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].
agg_cost);
291 tuple = heap_form_tuple(tuple_desc, values, nulls);
292 result = HeapTupleGetDatum(tuple);
293 SRF_RETURN_NEXT(funcctx, result);
302 SRF_RETURN_DONE(funcctx);