Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix(cypher): the early WHERE pass waits for every alias a condition reads
Martin Vogel6d2d30c3ea21
diff --git a/src/cypher/cypher.c b/src/cypher/cypher.cindex 8eaae7a26..c86be43bf 100644--- a/src/cypher/cypher.c+++ b/src/cypher/cypher.c@@ -2899,12 +2899,23 @@ static cyp_partial_t partial_or(cyp_partial_t l, cyp_partial_t r) {: CYP_PARTIAL_UNKNOWN;}-/* A condition whose alias is not bound yet is UNKNOWN; a literal-only LHS- * (func condition with no variable arg) has nothing to wait for. */+static bool partial_alias_unbound(binding_t *b, const char *alias) {+ return alias && !binding_get(b, alias) && !binding_get_edge(b, alias);+}++/* A condition is UNKNOWN while any alias it reads is not bound yet: its own+ * variable, and every function argument's -- a func condition is filed under+ * its first argument's alias, so the b in coalesce(a.x, b.name) is only seen+ * here. A literal-only LHS has nothing to wait for. */static cyp_partial_t eval_condition_partial(const cbm_condition_t *c, binding_t *b) {- if (c->variable && !binding_get(b, c->variable) && !binding_get_edge(b, c->variable)) {+ if (partial_alias_unbound(b, c->variable)) {return CYP_PARTIAL_UNKNOWN;}+ for (int i = 0; i < c->arg_count; i++) {+ if (partial_alias_unbound(b, c->args[i].variable)) {+ return CYP_PARTIAL_UNKNOWN;+ }+ }return eval_condition(c, b) ? CYP_PARTIAL_TRUE : CYP_PARTIAL_FALSE;}diff --git a/tests/test_cypher.c b/tests/test_cypher.cindex 06c3131da..ec3afbfc2 100644--- a/tests/test_cypher.c+++ b/tests/test_cypher.c@@ -3463,6 +3463,27 @@ TEST(cypher_exec_where_not_target_node_count) {PASS();}+/* The early WHERE pass must wait for every alias a condition reads. A function+ * condition is filed under its first argument's alias, so in+ * coalesce(a.no_such_prop, b.name) the target b hid behind the bound a: the+ * seed row read coalesce(NULL, <unbound b>) as a definite mismatch and pruned+ * every row before CALLS expansion, while the same predicate after WITH was+ * right. */+TEST(cypher_exec_where_func_arg_on_unbound_target) {+ cbm_store_t *s = setup_cypher_store();+ cbm_cypher_result_t r = {0};+ int rc = cbm_cypher_execute(s,+ "MATCH (a)-[:CALLS]->(b) WHERE coalesce(a.no_such_prop, b.name) = "+ "\"SubmitOrder\" RETURN a.name",+ "test", 0, &r);+ ASSERT_EQ(rc, 0);+ ASSERT_EQ(r.row_count, 1);+ ASSERT_STR_EQ(r.rows[0][0], "ValidateOrder");+ cbm_cypher_result_free(&r);+ cbm_store_close(s);+ PASS();+}+TEST(cypher_exec_where_in) {cbm_store_t *s = setup_cypher_store();cbm_cypher_result_t r = {0};@@ -6332,6 +6353,7 @@ SUITE(cypher) {RUN_TEST(cypher_exec_where_not_target_relationship);RUN_TEST(cypher_exec_where_not_source_node);RUN_TEST(cypher_exec_where_not_target_node_count);+ RUN_TEST(cypher_exec_where_func_arg_on_unbound_target);RUN_TEST(cypher_exec_where_in);RUN_TEST(cypher_exec_where_not_in);RUN_TEST(cypher_exec_where_is_null);