MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / execute_single

Function execute_single

src/cypher/cypher.c:4827–4894  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4825}
4826
4827static int execute_single(cbm_store_t *store, cbm_query_t *q, const char *project, int max_rows,
4828 result_builder_t *rb) {
4829 cbm_pattern_t *pat0 = &q->patterns[0];
4830
4831 /* Step 1: Scan initial nodes */
4832 cbm_node_t *scanned = NULL;
4833 int scan_count = 0;
4834 scan_pattern_nodes(store, project, max_rows, &pat0->nodes[0], &scanned, &scan_count);
4835
4836 /* Build initial bindings with early WHERE */
4837 int bind_cap = scan_count > max_rows ? scan_count : (max_rows > 0 ? max_rows : SKIP_ONE);
4838 binding_t *bindings = malloc((bind_cap + SKIP_ONE) * sizeof(binding_t));
4839 int bind_count = 0;
4840 const char *var_name = pat0->nodes[0].variable ? pat0->nodes[0].variable : "_n0";
4841
4842 for (int i = 0; i < scan_count && bind_count < bind_cap; i++) {
4843 if ((i & CYPHER_DEADLINE_CHECK_MASK) == 0 && cypher_deadline_exceeded()) {
4844 break;
4845 }
4846 binding_t b = {0};
4847 b.store = store;
4848 binding_set(&b, var_name, &scanned[i]);
4849 bool pass = !q->where || eval_where(q->where, &b);
4850 if (pass) {
4851 bindings[bind_count++] = b;
4852 } else {
4853 binding_free(&b);
4854 }
4855 }
4856
4857 /* Step 2: Expand first pattern's relationships */
4858 expand_pattern_rels(store, pat0, &bindings, &bind_count, &bind_cap, &var_name,
4859 q->pattern_optional[0]);
4860
4861 /* Step 2b: Additional patterns */
4862 if (expand_additional_patterns(store, q, project, max_rows, &bindings, &bind_count,
4863 &bind_cap) != 0) {
4864 for (int bi = 0; bi < bind_count; bi++) {
4865 binding_free(&bindings[bi]);
4866 }
4867 free(bindings);
4868 cbm_store_free_nodes(scanned, scan_count);
4869 return CBM_NOT_FOUND; /* cross-join allocation refused/failed */
4870 }
4871
4872 /* Step 3: Late WHERE */
4873 if (q->where && (pat0->rel_count > 0 || q->pattern_count > SKIP_ONE)) {
4874 filter_bindings_where(q->where, bindings, &bind_count);
4875 }
4876
4877 /* Step 3b: WITH clause */
4878 execute_with_clause(q, &bindings, &bind_count);
4879
4880 /* Step 4: Project results */
4881 rb_init(rb);
4882 if (q->ret) {
4883 execute_return_clause(q, q->ret, bindings, bind_count, max_rows, rb);
4884 } else {

Callers 1

cbm_cypher_executeFunction · 0.85

Calls 13

scan_pattern_nodesFunction · 0.85
cypher_deadline_exceededFunction · 0.85
binding_setFunction · 0.85
eval_whereFunction · 0.85
binding_freeFunction · 0.85
expand_pattern_relsFunction · 0.85
cbm_store_free_nodesFunction · 0.85
filter_bindings_whereFunction · 0.85
execute_with_clauseFunction · 0.85
rb_initFunction · 0.85
execute_return_clauseFunction · 0.85

Tested by

no test coverage detected