Skip to content

Commit 6d2d30c

Browse files
fix(cypher): the early WHERE pass waits for every alias a condition reads
eval_condition_partial (from DeusData#2253) answers UNKNOWN for a condition whose alias is not bound yet, but it only looked at c->variable. A function condition is filed under its first argument's alias, so in MATCH (a)-[:CALLS]->(b) WHERE coalesce(a.no_such_prop, b.name) = 'x' the seed row saw a bound a, read coalesce(NULL, <unbound b>) as a definite mismatch and pruned every row before CALLS expansion: zero rows, while the same predicate after WITH returned the right ones. Check every function argument's alias as well, the way this branch's original fix did (condition_bindings_available), inside main's three-valued leaf. RED before: cypher_exec_where_func_arg_on_unbound_target, row_count 0, expected 1. GREEN after; cypher suite 237 passed. Co-authored-by: lorenzozanee <wyz0707@proton.me> Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 146daa9 commit 6d2d30c

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

‎src/cypher/cypher.c‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,12 +2899,23 @@ static cyp_partial_t partial_or(cyp_partial_t l, cyp_partial_t r) {
28992899
: CYP_PARTIAL_UNKNOWN;
29002900
}
29012901

2902-
/* A condition whose alias is not bound yet is UNKNOWN; a literal-only LHS
2903-
* (func condition with no variable arg) has nothing to wait for. */
2902+
static bool partial_alias_unbound(binding_t *b, const char *alias) {
2903+
return alias && !binding_get(b, alias) && !binding_get_edge(b, alias);
2904+
}
2905+
2906+
/* A condition is UNKNOWN while any alias it reads is not bound yet: its own
2907+
* variable, and every function argument's -- a func condition is filed under
2908+
* its first argument's alias, so the b in coalesce(a.x, b.name) is only seen
2909+
* here. A literal-only LHS has nothing to wait for. */
29042910
static cyp_partial_t eval_condition_partial(const cbm_condition_t *c, binding_t *b) {
2905-
if (c->variable && !binding_get(b, c->variable) && !binding_get_edge(b, c->variable)) {
2911+
if (partial_alias_unbound(b, c->variable)) {
29062912
return CYP_PARTIAL_UNKNOWN;
29072913
}
2914+
for (int i = 0; i < c->arg_count; i++) {
2915+
if (partial_alias_unbound(b, c->args[i].variable)) {
2916+
return CYP_PARTIAL_UNKNOWN;
2917+
}
2918+
}
29082919
return eval_condition(c, b) ? CYP_PARTIAL_TRUE : CYP_PARTIAL_FALSE;
29092920
}
29102921

‎tests/test_cypher.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3463,6 +3463,27 @@ TEST(cypher_exec_where_not_target_node_count) {
34633463
PASS();
34643464
}
34653465

3466+
/* The early WHERE pass must wait for every alias a condition reads. A function
3467+
* condition is filed under its first argument's alias, so in
3468+
* coalesce(a.no_such_prop, b.name) the target b hid behind the bound a: the
3469+
* seed row read coalesce(NULL, <unbound b>) as a definite mismatch and pruned
3470+
* every row before CALLS expansion, while the same predicate after WITH was
3471+
* right. */
3472+
TEST(cypher_exec_where_func_arg_on_unbound_target) {
3473+
cbm_store_t *s = setup_cypher_store();
3474+
cbm_cypher_result_t r = {0};
3475+
int rc = cbm_cypher_execute(s,
3476+
"MATCH (a)-[:CALLS]->(b) WHERE coalesce(a.no_such_prop, b.name) = "
3477+
"\"SubmitOrder\" RETURN a.name",
3478+
"test", 0, &r);
3479+
ASSERT_EQ(rc, 0);
3480+
ASSERT_EQ(r.row_count, 1);
3481+
ASSERT_STR_EQ(r.rows[0][0], "ValidateOrder");
3482+
cbm_cypher_result_free(&r);
3483+
cbm_store_close(s);
3484+
PASS();
3485+
}
3486+
34663487
TEST(cypher_exec_where_in) {
34673488
cbm_store_t *s = setup_cypher_store();
34683489
cbm_cypher_result_t r = {0};
@@ -6332,6 +6353,7 @@ SUITE(cypher) {
63326353
RUN_TEST(cypher_exec_where_not_target_relationship);
63336354
RUN_TEST(cypher_exec_where_not_source_node);
63346355
RUN_TEST(cypher_exec_where_not_target_node_count);
6356+
RUN_TEST(cypher_exec_where_func_arg_on_unbound_target);
63356357
RUN_TEST(cypher_exec_where_in);
63366358
RUN_TEST(cypher_exec_where_not_in);
63376359
RUN_TEST(cypher_exec_where_is_null);

0 commit comments

Comments
 (0)