Skip to content

fix(#6577): OR with a non-cursor-buildable operator (NEQ/LIKE/ILIKE) silently drops rows - #6684

Merged
robfrank merged 1 commit into
mainfrom
fix/6577-or-neq-like-drops-branch
Aug 24, 2026
Merged

robfrank merged 1 commit into
mainfrom
fix/6577-or-neq-like-drops-branch

Conversation

@robfrank

@robfrank robfrank commented Aug 24, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #6577

Summary

SelectExecutor.isTheNodeFullyIndexed() (used by filterWithIndexesFinalNode()'s "under an OR, both sides must be indexed" gate) only excluded is_null/is_not_null from "this leaf is indexed" - every other operator on an indexed property, including neq/like/ilike, was treated as indexed as long as the property had an index. But filterWithIndexesFinalNode()'s cursor-building switch only knows how to build a cursor for eq/in_op/between/gt/ge/lt/le; a neq/like/ilike leaf falls through to a bare return and contributes no cursor at all.

So for a != 'nonexistent' OR n = -1: the "both sides indexed" gate passed (both properties have indexes), the neq leaf silently contributed zero cursors, and the eq leaf's cursor alone became the entire candidate stream - every record matching only the neq branch was silently dropped from the result. This is a missing-rows correctness bug, not a performance one.

The fix extracts the operator set filterWithIndexesFinalNode() can actually turn into a cursor (eq, in_op, between, gt, ge, lt, le) into one shared CURSOR_BUILDABLE_OPERATORS field, and has isTheNodeFullyIndexed() key its "is this leaf indexed" check off that same set instead of the narrower is_null/is_not_null exclusion - mirroring the suggested fix in the issue so the two call sites can no longer independently drift apart the way this bug happened in the first place. filterWithIndexesFinalNode() also gets a cheap defensive early-return against the same set, as a mirror of its own switch in case the invariant is ever loosened elsewhere.

A neq/like/ilike leaf under an OR now correctly falls back to a full scan for that branch (which isTheNodeFullyIndexed()'s or case already unions with ||, so the overall query still uses whatever index it can and only loses the "both sides indexed" fast path) instead of silently losing rows.

Test plan

New regression test Issue6577OrWithNonCursorBuildableOperatorTest (engine/src/test/java/com/arcadedb/query/select/), reproducing the issue's exact scenario plus siblings:

  • orWithNeqOnOneSideMustNotDropTheOtherBranch - the issue's repro (a != 'nonexistent' OR n = -1), asserts all 1000 rows are returned.
  • orWithNeqOnOneSideMustNotDropTheOtherBranchReversed - same shape with neq on the right-hand side of the or.
  • orWithLikeOnOneSideMustNotDropTheOtherBranch / orWithIlikeOnOneSideMustNotDropTheOtherBranch - same defect via like/ilike.
  • orWithNeqOnBothSidesFallsBackToFullScanCorrectly - both branches non-cursor-buildable, verifying the pre-existing full-scan fallback stays correct.

Verified:

  • All 5 new tests fail against main (0L instead of 1000L) before the fix, confirming they reproduce the bug.
  • All 5 new tests pass after the fix.
  • Full com.arcadedb.query.select package regression suite (115 tests across Issue6565SelectIndexCandidateLimitTest, SelectCompositeIndexTest, SelectExecutionTest, SelectIndexExecutionTest, SelectOperatorsExtendedTest, SelectOrderByTest, SelectParallelIteratorTest, SelectTraversalTest, SelectVectorTest, plus the new test) passes with no regressions.
  • mvn -pl engine -am compile succeeds cleanly.

Summary by CodeRabbit

  • Bug Fixes
    • Improved query results for OR conditions involving neq, like, and ilike operators.
    • These queries now correctly evaluate all matching records instead of incorrectly returning incomplete or empty results.
  • Tests
    • Added regression coverage for indexed string and integer fields, including varied operator and condition ordering.

isTheNodeFullyIndexed() only excluded is_null/is_not_null from "this leaf
is indexed"; every other operator on an indexed property (neq/like/ilike)
was treated as indexed even though filterWithIndexesFinalNode()'s
cursor-building switch has no case for them and silently falls through to
a bare return, contributing zero cursors.

Under an OR whose "both sides indexed" gate then passed on that looser
check, the neq/like/ilike branch contributed no rows at all while its
sibling's cursor became the entire candidate stream - a correctness bug,
not a performance one: matching records were silently dropped.

Extract the operator set filterWithIndexesFinalNode() can actually build a
cursor for (eq/in_op/between/gt/ge/lt/le) into one shared
CURSOR_BUILDABLE_OPERATORS field, and have isTheNodeFullyIndexed() key its
"is this leaf indexed" check off it instead of the narrower
is_null/is_not_null exclusion, so the two can no longer independently
drift the way this bug happened in the first place.
@coderabbitai

coderabbitai Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6dfab879-1301-46b8-8f16-9f3c310a6997

📥 Commits

Reviewing files that changed from the base of the PR and between 7e716af and 0af07c7.

📒 Files selected for processing (2)
  • engine/src/main/java/com/arcadedb/query/select/SelectExecutor.java
  • engine/src/test/java/com/arcadedb/query/select/Issue6577OrWithNonCursorBuildableOperatorTest.java

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

SelectExecutor now shares one operator set for index-cursor eligibility. Unsupported neq, like, and ilike predicates use full-scan evaluation. New tests cover OR queries and verify that all matching rows remain in the result.

Changes

Cursor-buildability fallback

Layer / File(s) Summary
Align index detection with cursor construction
engine/src/main/java/com/arcadedb/query/select/SelectExecutor.java
A shared operator set identifies cursor-buildable operators. Leaf index detection and final filtering reject unsupported operators, including neq, like, and ilike.
Validate complete OR results
engine/src/test/java/com/arcadedb/query/select/Issue6577OrWithNonCursorBuildableOperatorTest.java
A 1,000-row indexed fixture tests OR queries with neq, like, and ilike branches in both operand orders and with non-cursor-buildable operators on both sides.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 0af07

The PR corrects index handling for non-cursor-buildable operators and adds regression coverage; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: lvca

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the fix for issue #6577 and names the affected OR operators.
Description check ✅ Passed The description explains the root cause, fix, linked issue, regression tests, and verification results in sufficient detail.
Linked Issues check ✅ Passed The changes satisfy issue #6577 by preventing dropped rows and synchronizing cursor-buildable operator detection with cursor construction.
Out of Scope Changes check ✅ Passed The source change and five regression tests directly support issue #6577 without unrelated code changes.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/6577-or-neq-like-drops-branch

Comment @coderabbitai help to get the list of available commands.

@codacy-production

codacy-production Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

🟢 Coverage 75.00% diff coverage · -6.48% coverage variation

Metric Results
Coverage variation ✅ -6.48% coverage variation
Diff coverage ✅ 75.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (e7dc2fc) 165763 132646 80.02%
Head commit (0af07c7) 198153 (+32390) 145719 (+13073) 73.54% (-6.48%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#6684) 4 3 75.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@mergify

mergify Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@claude

claude Bot commented Aug 24, 2026

Copy link
Copy Markdown

Review

Nicely scoped fix for a real correctness bug (silent row-dropping under OR with neq/like/ilike), and the write-up in the PR description makes the root cause very easy to verify against the code.

Correctness

  • Verified the fix against the full SelectOperator enum: the leaf operators are eq, neq, lt, le, gt, ge, ilike, like, in_op, between, is_null, is_not_null. CURSOR_BUILDABLE_OPERATORS lists exactly the seven the filterWithIndexesFinalNode() switch can turn into a cursor, so isTheNodeFullyIndexed() now excludes precisely the operators that used to fall through to a bare return (neq, like, ilike, plus the pre-existing is_null/is_not_null). That matches the switch statement one-to-one.
  • Traced the call graph: lookForIndexes() runs isTheNodeFullyIndexed(select.rootTreeElement) over the whole tree before filterWithIndexes(), and that's the only place node.index gets set for the single-property path. So with this fix, a neq/like/ilike leaf's node.index is never set to non-null in the first place - the new guard added in filterWithIndexesFinalNode() is therefore currently unreachable dead code given the single call path today. The PR description acknowledges this explicitly ("cheap defensive mirror... in case the invariant is ever loosened elsewhere"), which is a reasonable trade-off given this is exactly the class of bug being fixed (two call sites silently drifting apart), but it's worth being aware it's belt-and-suspenders rather than load-bearing today.
  • The AND and not branches of isTheNodeFullyIndexed() are unaffected (|| semantics for AND still correctly falls back to filtering the unindexed side in memory), and the fix doesn't touch matchCompositeIndex()'s separate composite-index path, which is out of scope here since it already restricts itself to eq leaves via collectAndEqLeaves().

Test coverage

  • Good set of regression tests: neq on both sides of the or (left and reversed), like, ilike, and a both-sides-non-buildable fallback case. The PR description states all 5 fail on main and pass after the fix, and that the full select package suite (115 tests) stays green - that's exactly the right verification loop per the repo's TDD guidance.
  • Minor nit: the new test class doesn't assert anything about which/whether an index was actually used (e.g. via usedIndexes/metrics) - it only asserts row counts. That's sufficient to catch the specific regression (missing rows), but wouldn't catch a future change that keeps correctness but silently stops using any index in the "both sides indexed" fast path. Not a blocker, just noting the coverage boundary.

Style / minor

  • The extracted CURSOR_BUILDABLE_OPERATORS field is a good move - eliminates exactly the kind of two-call-site drift that caused the bug. EnumSet.of(...) is the right lightweight choice here (matches the project's performance/low-GC guidance).
  • Comment density is heavy (multi-line, all-caps blocks at nearly every touched line), but it's consistent with the pre-existing style already present in this file, so not out of place.

Overall this looks correct and well-tested. I wasn't able to execute mvn in this review sandbox to independently re-run the suite, but the logic traces cleanly against the full operator enum and the existing call graph, and the PR's own verification steps look sound.

@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.35%. Comparing base (e7dc2fc) to head (0af07c7).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...java/com/arcadedb/query/select/SelectExecutor.java 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6684      +/-   ##
==========================================
- Coverage   71.36%   71.35%   -0.02%     
==========================================
  Files        1871     1871              
  Lines      165763   165766       +3     
  Branches    35050    35051       +1     
==========================================
- Hits       118302   118286      -16     
- Misses      33157    33170      +13     
- Partials    14304    14310       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@robfrank
robfrank merged commit b5235ee into main Aug 24, 2026
30 of 35 checks passed
@robfrank
robfrank deleted the fix/6577-or-neq-like-drops-branch branch August 26, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native select: OR with a non-cursor-buildable operator (NEQ/LIKE/ILIKE) on one side silently drops the whole other branch

1 participant