Skip to content

fix(cypher): early WHERE pass waits for function-argument aliases; #2250 regression tests - #2502

Merged
DeusData merged 4 commits into
DeusData:mainfrom
lorenzozanee:fix/query-graph-where-not-target
Oct 21, 2026
Merged

DeusData merged 4 commits into
DeusData:mainfrom
lorenzozanee:fix/query-graph-where-not-target

Conversation

@lorenzozanee

Copy link
Copy Markdown
Contributor

The early WHERE pass evaluated predicates before relationship targets were bound, so NOT could discard rows that should reach the completed MATCH. The query engine now defers that pass until each referenced variable is available; the full WHERE filter still runs after relationship expansion. Regression tests cover target nodes, relationship properties, source-node behavior, aggregation, and equivalent predicate forms.

Cypher suite: 213/213 passed. Full suite: 8,313 passed, 17 unrelated CLI permission tests failed in the shared 0775 workspace, and 9 were skipped. scripts/lint.sh was incomplete because clang-tidy, cppcheck, and clang-format are unavailable on the host. Written with OpenAI Codex assistance on behalf of the submitting account owner.

Fixes #2250

Signed-off-by: lorenzozanee <wyz0707@proton.me>
@lorenzozanee
lorenzozanee requested a review from DeusData as a code owner October 3, 2026 05:50
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown

Thanks for opening this — it has been seen, and it is queued.

This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence.

Current review status: working through a backlog. 0.9.1-rc.1 is out, so the release freeze that held reviews is over — but it left a large queue of open pull requests behind it, and we are reading through them oldest-first. The background is in discussion #1144.

What that means for this PR, concretely:

  • It will not be closed for inactivity. No stale bot touches pull requests here.
  • It may still sit a while before a human reads it. That is on us, not on you.
  • Older PRs are read first, so a recent one is not being skipped — it is behind a queue.

Things that will genuinely speed it up whenever review does happen:

  • Keep it rebased on main — the tree is moving quickly right now, and a conflicting branch cannot be reviewed as the diff you intended.
  • Get CI green, or say which failures you believe are pre-existing.
  • Keep the change to one claim. Bundled features and refactors get split before they get merged, which costs you a round trip.
  • Every commit needs a sign-off (git commit -s) — CI enforces DCO.

If this fixes a bug, a reproduction we can run is worth more than a description of the symptom.

Thanks for contributing, and sorry in advance for the wait.

@DeusData DeusData added bug Something isn't working cypher Cypher query language parser/executor bugs priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. labels Oct 19, 2026
@DeusData

Copy link
Copy Markdown
Owner

Thank you for tackling the early WHERE filtering problem and adding regression coverage. Sorry this has waited for a maintainer response.

While this PR was waiting, #2253 landed a related three-valued early-filter implementation, distilled from Andrew Hundt's #1245. In current main, unbound aliases produce UNKNOWN during the partial evaluation, NOT preserves UNKNOWN, and the early pass only drops definitively false rows; the full filter still runs after relationship expansion (partial evaluation, execution path). That merge happened after you opened this PR.

The next maintainer step is to compare your implementation and regression cases against that change, so we can identify any remaining gaps and preserve useful coverage and credit. We are not treating this as automatically superseded, and have not independently verified the test results reported here. Please hold off on routine rebases until that comparison is done. The review queue is full, but the delay is ours; thank you for contributing and for your patience.

DeusData and others added 3 commits October 20, 2026 19:23
…rseded

The early WHERE pass in execute_single runs on seed rows where only the
first alias is bound, so a NOT on the target node or the relationship
pruned every row (DeusData#2250). This branch fixed that by skipping the early
pass until every alias the WHERE reads was bound.

While it waited for review, DeusData#2253 (8ab555e) landed the same fix on
main as a three-valued early pass: an unbound alias is UNKNOWN, NOT
keeps it UNKNOWN, and only a definite FALSE prunes. This branch's
regression tests pass on main's production code unchanged, so restore
src/cypher/cypher.c to the branch's base and keep the tests; the merge
of main that follows takes main's implementation.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Conflict in tests/test_cypher.c: both sides added WHERE NOT regression
tests right after cypher_exec_where_not. Kept both sets, main's four
DeusData#2253 tests first, then this branch's four, with their RUN_TEST lines in
the same order. src/cypher/cypher.c merged cleanly to main's version.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
…eads

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>
@DeusData DeusData changed the title fix(cypher): defer WHERE filtering until referenced variables are available fix(cypher): early WHERE pass waits for function-argument aliases; #2250 regression tests Oct 20, 2026
@DeusData

Copy link
Copy Markdown
Owner

Thank you, @lorenzozanee, for taking on #2250 and for such a careful set of regression cases. Covering the target node, a relationship property, the source-node control, the count(*) shape and the equivalent <> / OR / WITH forms is exactly the comparison the issue needed, and your binding check turned out to matter beyond the case it was written for.

As promised in the earlier note, we compared your branch with #2253, which landed a related early-WHERE fix on main after you opened this PR. Here is what we found and what we pushed on top of your commit (your commit is unchanged):

  1. All of your regression tests pass on main's current Cypher code without your change to cypher.c, and the reporter's full query table from query_graph: WHERE NOT <predicate> on the target node or relationship of a MATCH pattern silently returns 0 rows — same predicate with <>, inside OR, or after WITH returns the right rows #2250 (all 25 forms, on their 3-file fixture) now returns the expected numbers. So, in a separate commit, we dropped the cypher.c part in favour of main's version. That also clears the lint failure, which was a line-wrapping nit inside that hunk.
  2. We merged current main into the branch. Both sides had added tests in the same place, so the merge keeps both sets: main's four tests from fix(cypher): stop the early WHERE pruning rows it cannot judge yet #2253 first, then your four.
  3. The comparison turned up one case that main still gets wrong and your approach handled: a function condition whose later argument names the not-yet-bound side of the pattern, for example WHERE coalesce(a.x, b.name) = 'SubmitOrder', which returned zero rows. Your condition_bindings_available checked every argument's variable; main's check only looked at the first one. We ported that per-argument check into main's evaluator and added a regression test for it (it fails without the change and passes with it). That commit credits you as co-author.

We also retitled the PR to describe what it now contains. Once CI is green on the updated branch, it goes to the final merge review. Thank you for your patience while it waited, and for a contribution that improved the fix on main as well.

@DeusData
DeusData merged commit 3457b21 into DeusData:main Oct 21, 2026
27 checks passed
@DeusData

Copy link
Copy Markdown
Owner

Thank you for the Cypher alias-handling fix and the regression tests! The reviewed change passed the required CI checks and merged cleanly with current main in 3457b21. Thanks again for improving query correctness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cypher Cypher query language parser/executor bugs priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.

Projects

None yet

2 participants