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

Function execute_single

src/cypher/cypher.c:4821–4888  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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