33 #include "utils/array.h"
51 char *combinations_sql,
57 size_t *result_count) {
62 size_t size_start_vidsArr = 0;
63 int64_t *start_vidsArr = NULL;
65 size_t size_end_vidsArr = 0;
66 int64_t *end_vidsArr = NULL;
68 size_t total_combinations = 0;
72 start_vidsArr = (int64_t*)
74 end_vidsArr = (int64_t*)
76 }
else if (combinations_sql) {
78 if (total_combinations == 0) {
86 (*result_tuples) = NULL;
91 size_t total_edges = 0;
94 PGR_DBG(
"Total %ld edges in query:", total_edges);
96 if (total_edges == 0) {
105 PGR_DBG(
"Starting processing");
106 clock_t start_t = clock();
107 char *log_msg = NULL;
108 char *notice_msg = NULL;
109 char *err_msg = NULL;
115 start_vidsArr, size_start_vidsArr,
116 end_vidsArr, size_end_vidsArr,
127 time_msg(
" processing pgr_binaryBreadthFirstSearch", start_t, clock());
128 PGR_DBG(
"Returning %ld tuples", *result_count);
132 pfree(*result_tuples);
147 pfree(start_vidsArr);
154 FuncCallContext *funcctx;
155 TupleDesc tuple_desc;
159 size_t result_count = 0;
162 if (SRF_IS_FIRSTCALL()) {
163 MemoryContext oldcontext;
164 funcctx = SRF_FIRSTCALL_INIT();
165 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
176 if (PG_NARGS() == 4) {
181 text_to_cstring(PG_GETARG_TEXT_P(0)),
183 PG_GETARG_ARRAYTYPE_P(1),
184 PG_GETARG_ARRAYTYPE_P(2),
189 }
else if (PG_NARGS() == 3) {
194 text_to_cstring(PG_GETARG_TEXT_P(0)),
195 text_to_cstring(PG_GETARG_TEXT_P(1)),
206 #if PGSQL_VERSION > 95
207 funcctx->max_calls = result_count;
209 funcctx->max_calls = (uint32_t)result_count;
211 funcctx->user_fctx = result_tuples;
212 if (get_call_result_type(fcinfo, NULL, &tuple_desc) != TYPEFUNC_COMPOSITE) {
214 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
215 errmsg(
"function returning record called in context "
216 "that cannot accept type record")));
219 funcctx->tuple_desc = tuple_desc;
220 MemoryContextSwitchTo(oldcontext);
223 funcctx = SRF_PERCALL_SETUP();
224 tuple_desc = funcctx->tuple_desc;
227 if (funcctx->call_cntr < funcctx->max_calls) {
246 values = palloc(numb *
sizeof(Datum));
247 nulls = palloc(numb *
sizeof(
bool));
250 for (i = 0; i < numb; ++i) {
254 values[0] = Int32GetDatum(funcctx->call_cntr + 1);
255 values[1] = Int32GetDatum(result_tuples[funcctx->call_cntr].
seq);
256 values[2] = Int64GetDatum(result_tuples[funcctx->call_cntr].
start_id);
257 values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].
end_id);
258 values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].
node);
259 values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].
edge);
260 values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].
cost);
261 values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].
agg_cost);
265 tuple = heap_form_tuple(tuple_desc, values, nulls);
266 result = HeapTupleGetDatum(tuple);
267 SRF_RETURN_NEXT(funcctx, result);
275 SRF_RETURN_DONE(funcctx);