Repository navigation
fix(#5966): BETWEEN on an indexed column now uses the index; dedupe declared-type key conversion - #6018
Conversation
…eclared-type key conversion BETWEEN on an indexed column always fell back to a full bucket scan, unlike the semantically identical `x > a AND x < b`. BetweenCondition never implemented BooleanExpression.isIndexAware(), so the planner's index-search descriptor builder never recognized it as an index-range candidate. Added the override (mirroring BinaryCondition's), and made the range-terminal detection in SelectExecutionPlanner recognize BetweenCondition too, so a BETWEEN in the middle of a composite index correctly stops key-building at that field instead of letting a later equality field be folded into the same ordered-range lookup. IndexSearchDescriptor and FetchFromIndexStep's cost/stats paths get the matching BetweenCondition-awareness so they don't force an unnecessary DISTINCT step or mis-bucket the query cost. Also collapses LSMTreeIndex.convertKeys(Object[]) into a delegate to LSMTreeIndexAbstract.convertKeysToDeclaredTypes(), removing one of three independent copies of "narrow to declared type + fold collation" that #5932 showed can silently drift apart. Co-Authored-By: Luca Garulli <l.garulli@arcadedata.com>
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 2 |
🟢 Coverage 80.00% diff coverage · -6.47% coverage variation
Metric Results Coverage variation ✅ -6.47% coverage variation Diff coverage ✅ 80.00% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (1283d66) 153996 119908 77.86% Head commit (8f7c465) 186329 (+32333) 133026 (+13118) 71.39% (-6.47%) 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 (#6018) 10 8 80.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.
ReviewWent through the diff in detail ( Code quality / correctness
Test coverageThe new
PerformanceNo concerns - this only changes planning-time branching ( SecurityNone identified - purely internal query-planning and index-key-conversion logic, no new external input handling. Overall this is a well-scoped, well-explained fix with good regression coverage for the primary reported issue. I didn't find any correctness bugs in the diff itself. |
…NIQUE BETWEEN coverage Addresses the non-blocking test-coverage gaps raised in code review on PR #6018: - NOT BETWEEN on an indexed column still returns correct results (row-level path, untouched by the new isIndexAware()/rangeOp wiring). - BETWEEN on a COLLATE CI indexed STRING column uses the index and case-folds correctly, exercising the shared convertKeys()/convertKeysToDeclaredTypes() path. - BETWEEN as the first field of a composite UNIQUE index, exercising the refactored LSMTreeIndex.convertKeys() delegate on the insert side too. Co-Authored-By: Luca Garulli <l.garulli@arcadedata.com>
|
Addressed the test-coverage suggestions from the review in 356279a:
On the All 6 tests in |
Review: fix(#5966) — BETWEEN uses index; dedupe declared-type key conversionOverall this is a well-scoped, well-tested fix. The Finding: one more copy of the same "only BinaryCondition is understood" bug was missedThe PR fixes // engine/src/main/java/com/arcadedb/query/sql/executor/SelectExecutionPlanner.java:3480-3486
private boolean requiresMultipleIndexLookups(final AndBlock keyCondition) {
for (final BooleanExpression oBooleanExpression : keyCondition.getSubBlocks()) {
if (!(oBooleanExpression instanceof BinaryCondition)) {
return true;
}
}
return false;
}This one wasn't touched. It's used only from Given the PR's own narrative is "three independent copies of the same logic drifted apart, so we collapsed them" for the key-conversion half of this fix, it would be consistent to either update this method the same way Minor / non-blocking
TestsGood coverage, and the follow-up commit closing the NOT BETWEEN / CI-collation / composite-UNIQUE gaps raised in review is exactly right. One gap still open: no test exercises the multi-index No security concerns. Net performance win (BETWEEN now hits the index) with no new dependencies or public API changes. |
Code review on PR #6018 found a second private copy of the same "only BinaryCondition is understood" check, in SelectExecutionPlanner.createParallelIndexFetch(), that the first commit's fix to IndexSearchDescriptor.requiresMultipleIndexLookups() missed. Rather than patch both copies (which is exactly the kind of drift this PR's key-conversion dedupe was already about), removed SelectExecutionPlanner's private duplicate and pointed the call site at the already-fixed IndexSearchDescriptor instance method - one copy of the check instead of two. Also adds a regression test for an OR across two separately-indexed fields with a BETWEEN branch, confirming the merge produces exactly one top-level DISTINCT (not a redundant one per branch) and returns the correct union of rows. Co-Authored-By: Luca Garulli <l.garulli@arcadedata.com>
|
Addressed the code-review finding in 8f7c465: Third duplicate copy of "only BinaryCondition is understood" - fixed by removing the duplication, not patching it. Also added On the reviewer's "minor/non-blocking" note about All 7 tests in |
ReviewI read through the full diff (5 source files + the new Correctness
Minor, non-blocking observations
Test coverageStrong. The six tests in Nice cleanup consolidating three copies of "narrow to declared type + fold collation" into one path — that class of drift is exactly what caused #5932, so removing an entry point for it to recur is worthwhile beyond just this PR's main fix. |
|
Latest review pass found no correctness issues and confirmed the two fixes from the prior rounds. On the one minor, explicitly-optional observation - Waiting on |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6018 +/- ##
==========================================
+ Coverage 69.08% 69.22% +0.14%
==========================================
Files 1798 1798
Lines 153996 153986 -10
Branches 32586 32585 -1
==========================================
+ Hits 106392 106602 +210
+ Misses 34127 33908 -219
+ Partials 13477 13476 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
`ha-integration-tests` failed on this run with two test failures, both in the `ha-raft` module:
Both are Raft cluster convergence/timing assertions in `ha-raft`, a module this PR's diff never touches - the change here is scoped to `engine`'s SQL planner (`SelectExecutionPlanner`, `FetchFromIndexStep`, `IndexSearchDescriptor`, `BetweenCondition`) and `LSMTreeIndex`'s key-conversion dedupe, none of which is on the Raft commit/replication path these tests exercise. This matches the profile of this lane's known chronic flakiness under CI resource contention, unrelated to any specific diff. Triggered a rerun of the failed jobs (`gh run rerun --failed`) to confirm non-determinism rather than asserting it without evidence. |
|
Rerun of `ha-integration-tests` failed again, but with a different specific failure profile than the first run:
Both new failures are, again, Raft cluster timing/connection-convergence assertions in `ha-raft` (gRPC connection errors, `APPEND_ENTRIES` cancellations, ticket-release timing) - unrelated to this PR's diff. Different specific tests failing across independent runs is the signature of environment/timing non-determinism rather than a reproducible regression tied to a code change; a real regression from this PR's diff (SQL planner + LSM key-conversion, nothing in `ha-raft`) would fail the same assertion deterministically every run. Triggering another rerun. |
|
Third `ha-integration-tests` rerun failed again, this time with a single failure: `Issue5410AbandonedTicketReleaseIT.abandonedEntryReleasesItsPhase2TicketOnceApplied` (also seen in run 1; run 2 had it plus a different test). Checked whether this is specific to this branch by looking at recent CI runs on `main` itself (`gh run list --branch main --workflow=mvn-test.yml`): the last 4 completed runs on `main` all show `conclusion: failure`, and the most recent one (commit 8ea92f0, unrelated to #5966) failed both `ha-integration-tests` and `unit-tests` - a lane that passed cleanly on every attempt of this PR's run. This confirms the CI environment itself is currently red independent of any branch's diff; this PR isn't introducing or uniquely triggering the flake. Triggering one more rerun. Given main itself is failing the same lane right now, this may need to resolve on the infrastructure side rather than something fixable in this PR - will keep documenting outcomes either way. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 2 |
🟢 Coverage 80.00% diff coverage · -6.44% coverage variation
Metric Results Coverage variation ✅ -6.44% coverage variation Diff coverage ✅ 80.00% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (1283d66) 153996 119908 77.86% Head commit (8f7c465) 186329 (+32333) 133078 (+13170) 71.42% (-6.44%) 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 (#6018) 10 8 80.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.
|
Fourth `ha-integration-tests` rerun failed with yet another different test: `RaftPriorityRejoinIT` (an `Error`, not an assertion failure this time). Summary across all 4 attempts on this PR:
Four different failure combinations across four Raft cluster integration test classes, none overlapping with this PR's diff (SQL planner + LSM index key-conversion in Triggering a 5th rerun. I'll keep documenting outcomes, but at this point the evidence strongly supports that this PR is correctness-complete and blocked only by pre-existing CI infrastructure flakiness that also affects |
|
Fifth `ha-integration-tests` rerun: failed again, same test as runs 1-3: `Issue5410AbandonedTicketReleaseIT.abandonedEntryReleasesItsPhase2TicketOnceApplied` (4 of 5 runs now). This test was added in PR #5472 (fixing #5410) - it's an established test, not something new or touched by this PR. Status summary: the code review (`claude-review`) passed cleanly across two rounds with all valid points addressed (BETWEEN index-awareness, the composite-key rangeOp fix, the third duplicate-check removal, and the follow-up test coverage it asked for). Every other CI lane passes consistently on every attempt - `unit-tests`, `slow-unit-tests`, `integration-tests`, `vector-unit-tests`, `build-and-package`, all e2e suites, `opencypher-tck-tests`, static analysis. Only `ha-integration-tests` is unstable, and Continuing to rerun per the babysitting loop, but at this point further reruns are unlikely to add new information - the diagnosis is solid. This may need attention from whoever owns CI reliability for the `ha-raft` suite, separate from this PR. |
|
Sixth rerun: failed with two more different tests - `RaftReplicationMaterializedViewIT` and `Raft3PhaseCommitIT.basicInsertReplicates` - neither seen in any of the previous 5 runs. Running tally across 6 attempts, 8 distinct failures, 7 different test classes: `Issue5410AbandonedTicketReleaseIT` (×4), `Issue5569SlotMergeDeleteRaftIT`, `RemoteStickyConnectionStrategyIT`, `RaftPriorityRejoinIT`, `RaftReplicationMaterializedViewIT`, `Raft3PhaseCommitIT`. This is no longer "one flaky test" - it's broad instability across the whole `ha-raft` integration suite, consistent with the CI runner being under resource pressure during these 3-node Raft cluster tests (which are inherently timing-sensitive). Combined with `main` independently failing its last several runs on the same lane, I'm confident this is a CI infrastructure issue, not a defect in this PR. Triggering rerun #7. |
|
Seventh rerun: failed again, and worse than before - three distinct failures this time (`RemoteStickyConnectionStrategyIT`, `RaftPriorityRejoinIT`, `RaftRemoteReadYourWritesIT`) and the run took 1h6m instead of the usual ~56m. Final tally across 7 attempts: 9 distinct `ha-raft` test classes have failed at least once (`Issue5410AbandonedTicketReleaseIT` ×4, `RemoteStickyConnectionStrategyIT` ×2, `RaftPriorityRejoinIT` ×2, `Issue5569SlotMergeDeleteRaftIT`, `RaftReplicationMaterializedViewIT`, `Raft3PhaseCommitIT`, `RaftRemoteReadYourWritesIT`). The trend is getting worse, not better, and `main` itself was independently failing this same lane before this PR ever existed. This is CI infrastructure/resource contention affecting the whole `ha-raft` suite, not a defect this PR introduces or can fix - the diff here never touches that module. This PR is code-complete: the code review passed cleanly across two rounds with every valid point addressed, and every other CI lane (`unit-tests`, `slow-unit-tests`, `integration-tests`, `vector-unit-tests`, `build-and-package`, all e2e suites, static analysis) passes consistently. I'll keep retrying `ha-integration-tests` per the babysitting loop, but further identical reruns are unlikely to add new information at this point - this may need either a CI infra fix, an admin merge override, or the branch protection rule adjusted to not require this specific chronically-unstable lane. |
…pped in .toLowerCase() (#6036) * fix(#6033): BETWEEN on a COLLATE CI index now uses the index when wrapped in .toLowerCase() BinaryCondition.isIndexAware() already recognized field.toLowerCase() = 'value' against a CI index; BetweenCondition.isIndexAware() (added in #6018) only mirrored the plain-identifier branch, so field.toLowerCase() BETWEEN a AND b fell back to a full bucket scan. Extend BetweenCondition with the same CI-lowercase branch, reusing BinaryCondition's isFieldWithLowerCaseMethod() helper instead of duplicating it. * review: import assertj catchThrowable and CommandExecutionException instead of FQNs (#6033) * test(#6033): pin the negative paths of BetweenCondition's new CI-lowercase branch Add direct coverage for the two boundary cases the second review pass flagged as untested: field.toLowerCase() BETWEEN ... against a non-CI index, and an extra modifier chained after toLowerCase() on a CI index - both must still fall back to a full scan.
Summary
Two related fixes filed together in #5966, both follow-ups from the #5932/PR #5961 investigation:
1.
BETWEENon an indexed column never used the index, falling back to a full bucket scan with a row-level filter, unlike the semantically identicalx > a AND x < b:BetweenConditionnever overrodeBooleanExpression.isIndexAware(IndexSearchInfo), soSelectExecutionPlanner.buildIndexSearchDescriptor()never recognizedfield BETWEEN a AND bas an index-range-eligible shape. Added the override, mirroringBinaryCondition.isIndexAware().SelectExecutionPlanner's "is this condition terminal for composite-index key building" check (rangeOp) only recognizedBinaryCondition. Without also recognizingBetweenCondition, a query likeWHERE a = 1 AND b BETWEEN 10 AND 20 AND c = 1on a composite index(a, b, c)would have foldedc = 1into the same ordered-range key as an equality component after a range component - not just suboptimal, but a real correctness risk (proven by a test that fails without this half of the fix even though the plan does pick an index).IndexSearchDescriptor.requiresMultipleIndexLookups()/.cost()andFetchFromIndexStep.updateIndexStats()had the same "onlyBinaryConditionis understood" assumption, which would have forced an unnecessaryDISTINCTstep and mis-bucketed the query-cost cache for a matchedBETWEEN. Fixed alongside since they're the same class of gap on the same code path.BetweenCondition.resolveKeyFrom/resolveKeyTo/isKeyFromIncluded/isKeyToIncludedalready existed and are correct as-is; they were simply unreachable from the normal planning path before this change (only from the nicheSELECT FROM INDEX:<name> WHERE key BETWEEN a AND btarget syntax).2. Three independent copies of "narrow value to declared type + fold case-insensitive collation" existed:
LSMTreeIndex.convertKeys(Object[])(insert-side, feeds the transaction overlay),LSMTreeIndexAbstract.convertKeysToDeclaredTypes(Object[], byte[])(query-side range bounds), andLSMTreeIndexAbstract.convertKeys(Object[], byte[])(disk-probe, layers aString->byte[]encoding on top of the second one). The first two must stay behaviorally identical - they are the insert side and query side of the exact comparison whose divergence caused #5932'sClassCastException/silent-miscompare - but nothing enforced that. CollapsedLSMTreeIndex.convertKeys(Object[])into a one-line delegate toconvertKeysToDeclaredTypes(), matching how the disk-probe variant already delegates to it, so a future change to one can no longer silently diverge from the other.Test plan
Issue5966BetweenUsesIndexTest:betweenOnIndexedColumnUsesTheIndex- reproduces the issue's exact repro, asserts the plan containsFETCH FROM INDEX(not a bucket scan) and needs no row-levelFilterStep.betweenOnIndexedColumnReturnsSameResultsAsEquivalentAndRange- assertsBETWEENand the equivalent two-sidedANDreturn identical result sets, with both bounds inclusive.betweenInsideCompositeIndexStopsKeyBuildingAtTheRangeField- composite index(a, b, c)with aBETWEENon the middle field; asserts the index key used is only(a, b)andcis applied as a separate post-fetch filter, with correct row counts. Confirmed this test fails (wrong key/results) without theSelectExecutionPlannerhalf of the fix, even with theisIndexAwarehalf alone.com.arcadedb.index.**andcom.arcadedb.query.sql.executor.**test packages plus the composite-index/case-insensitive-index/max-min-from-index suites: all green, no regressions from either change.