Skip to content

fix(#5966): BETWEEN on an indexed column now uses the index; dedupe declared-type key conversion - #6018

Merged
lvca merged 3 commits into
mainfrom
fix/5966-between-index-dedup-keyconv
Aug 10, 2026
Merged

lvca merged 3 commits into
mainfrom
fix/5966-between-index-dedup-keyconv

Conversation

@lvca

@lvca lvca commented Aug 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Two related fixes filed together in #5966, both follow-ups from the #5932/PR #5961 investigation:

1. BETWEEN on an indexed column never used the index, falling back to a full bucket scan with a row-level filter, unlike the semantically identical x > a AND x < b:

  • BetweenCondition never overrode BooleanExpression.isIndexAware(IndexSearchInfo), so SelectExecutionPlanner.buildIndexSearchDescriptor() never recognized field BETWEEN a AND b as an index-range-eligible shape. Added the override, mirroring BinaryCondition.isIndexAware().
  • SelectExecutionPlanner's "is this condition terminal for composite-index key building" check (rangeOp) only recognized BinaryCondition. Without also recognizing BetweenCondition, a query like WHERE a = 1 AND b BETWEEN 10 AND 20 AND c = 1 on a composite index (a, b, c) would have folded c = 1 into 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() and FetchFromIndexStep.updateIndexStats() had the same "only BinaryCondition is understood" assumption, which would have forced an unnecessary DISTINCT step and mis-bucketed the query-cost cache for a matched BETWEEN. Fixed alongside since they're the same class of gap on the same code path.

BetweenCondition.resolveKeyFrom/resolveKeyTo/isKeyFromIncluded/isKeyToIncluded already existed and are correct as-is; they were simply unreachable from the normal planning path before this change (only from the niche SELECT FROM INDEX:<name> WHERE key BETWEEN a AND b target 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), and LSMTreeIndexAbstract.convertKeys(Object[], byte[]) (disk-probe, layers a String->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's ClassCastException/silent-miscompare - but nothing enforced that. Collapsed LSMTreeIndex.convertKeys(Object[]) into a one-line delegate to convertKeysToDeclaredTypes(), 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

  • New regression test Issue5966BetweenUsesIndexTest:
    • betweenOnIndexedColumnUsesTheIndex - reproduces the issue's exact repro, asserts the plan contains FETCH FROM INDEX (not a bucket scan) and needs no row-level FilterStep.
    • betweenOnIndexedColumnReturnsSameResultsAsEquivalentAndRange - asserts BETWEEN and the equivalent two-sided AND return identical result sets, with both bounds inclusive.
    • betweenInsideCompositeIndexStopsKeyBuildingAtTheRangeField - composite index (a, b, c) with a BETWEEN on the middle field; asserts the index key used is only (a, b) and c is applied as a separate post-fetch filter, with correct row counts. Confirmed this test fails (wrong key/results) without the SelectExecutionPlanner half of the fix, even with the isIndexAware half alone.
  • Verified all three assertions fail against the pre-fix code (reverted the fix locally, reran, confirmed the expected failures) and pass after restoring it.
  • Ran the full com.arcadedb.index.** and com.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.

…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>
@mergify

mergify Bot commented Aug 9, 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

@codacy-production

codacy-production Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 2 complexity

Metric Results
Complexity 2

View in Codacy

🟢 Coverage 80.00% diff coverage · -6.47% coverage variation

Metric Results
Coverage variation ✅ -6.47% coverage variation
Diff coverage ✅ 80.00% diff coverage

View coverage diff in Codacy

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.

@claude

claude Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review

Went through the diff in detail (BetweenCondition.isIndexAware, the SelectExecutionPlanner/IndexSearchDescriptor/FetchFromIndexStep range-terminal detection, and the LSMTreeIndex.convertKeys dedupe), plus the pre-existing infrastructure they plug into (resolveKeyFrom/resolveKeyTo/isKeyFromIncluded/isKeyToIncluded, FetchFromIndexStep.processAndBlock, BinaryCondition.createRangeWith). Static analysis only (build was sandboxed in this environment, so I couldn't run mvn verify myself) - the reasoning below is from reading the code paths, not from executing the new test.

Code quality / correctness

  • BetweenCondition.isIndexAware() mirrors BinaryCondition.isIndexAware()'s shape closely (base-identifier check on the field side, isEarlyCalculated on the bound expressions, gated by info.allowsRange()). Looks correct.
  • The new rangeOp detection in SelectExecutionPlanner.buildIndexSearchDescriptor() correctly makes BETWEEN terminal for composite-key building. I traced the interaction with the following "look for the opposite side of the range" loop (next.createRangeWith(singleExp)): BinaryCondition.createRangeWith() starts with if (!(match instanceof BinaryCondition ...)) return false;, so when singleExp is a BetweenCondition that loop safely no-ops instead of misfiring - good, since a BETWEEN already carries both bounds and doesn't need an additionalRangeCondition.
  • IndexSearchDescriptor.requiresMultipleIndexLookups()/.cost() and FetchFromIndexStep.updateIndexStats() additions are straightforward, consistent copies of the existing BinaryCondition handling (the latter already special-cased top-level condition instanceof BetweenCondition; this PR just extends the same treatment to the "last element of an AndBlock" case). No inconsistency found between the three sites.
  • FetchFromIndexStep.processAndBlock() (unchanged in this PR) builds keys via indexKeyFrom/indexKeyTo/indexKeyFromIncluded/indexKeyToIncluded, which call resolveKeyFrom/resolveKeyTo/isKeyFromIncluded/isKeyToIncluded - already implemented on BetweenCondition before this PR. So the new isIndexAware + rangeOp wiring is sufficient to route a BETWEEN into a code path that already knew how to consume it; nothing else needed changing there.
  • LSMTreeIndex.convertKeys(Object[]) -> mutable.convertKeysToDeclaredTypes(keys, mutable.binaryKeyTypes): verified LSMTreeIndex.getDatabase() already delegates to mutable.getDatabase(), so calling convertKeysToDeclaredTypes on mutable uses the identical database/caseInsensitiveKeys fields the old inlined code read via getDatabase()/mutable.caseInsensitiveKeys - behaviorally identical, good dedupe per the PR's stated goal of preventing the insert-side/query-side conversions from re-diverging (per LSMTreeIndexCursor compares raw (unconverted) range bounds against typed stored keys: ClassCastException on indexed range query with a numeric-string bound #5932).
  • NOT BETWEEN is parsed as BetweenCondition wrapped in a NotBlock (SQLASTBuilder.visitBetweenCondition), and NotBlock does not override isIndexAware(), so it correctly falls back to the BooleanExpression default (false) rather than being incorrectly treated as index-aware. Worth confirming this is intentional (i.e. no plan to ever push NOT BETWEEN into an index range) - it looks like the safe default either way.

Test coverage

The new Issue5966BetweenUsesIndexTest covers the three scenarios described in the PR body (plan shape, result-set equivalence with inclusive bounds, composite-index key truncation) reasonably well. A couple of gaps that could be worth adding, not blocking:

  • No test for NOT BETWEEN on an indexed column, to lock in that it still executes correctly (even if via a bucket scan) after this change.
  • No test for BETWEEN combined with a case-insensitive index (the PR touches the shared convertKeys/convertKeysToDeclaredTypes path, which has case-folding logic).
  • No test where BETWEEN is the first field of a composite index followed by more range/equality fields in different order, or where the index is UNIQUE (exercises the sub-index path touched indirectly by the LSMTreeIndex.convertKeys refactor).

Performance

No concerns - this only changes planning-time branching (isIndexAware, rangeOp) and replaces one inlined loop with an equivalent delegate call; no new allocations or hot-path overhead beyond what existed before (arguably fewer instances of duplicated per-key-conversion logic now).

Security

None 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>
@lvca

lvca commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

Addressed the test-coverage suggestions from the review in 356279a:

  • Added notBetweenOnIndexedColumnStillReturnsCorrectResults - confirms NOT BETWEEN still returns correct results after this change.
  • Added betweenOnCaseInsensitiveIndexedColumnUsesIndexAndFolds - BETWEEN on a COLLATE CI indexed STRING column uses the index and folds case correctly.
  • Added betweenAsFirstFieldOfCompositeUniqueIndex - BETWEEN as the first field of a composite UNIQUE index, which also exercises LSMTreeIndex.convertKeys() on the insert side (not just the query side the other tests cover).

On the NOT BETWEEN question: confirmed intentional - NotBlock correctly has no isIndexAware() override, so it keeps falling back to the pre-existing bucket-scan/row-filter path. This PR only adds index-range support for a bare BETWEEN; pushing NOT BETWEEN into an index range is a separate, unrelated enhancement (would need a "everything outside this range" index scan shape, not a simple range lookup) and out of scope for #5966.

All 6 tests in Issue5966BetweenUsesIndexTest pass, plus the composite-index/case-insensitive-index/max-min-from-index suites - no regressions.

@claude

claude Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review: fix(#5966) — BETWEEN uses index; dedupe declared-type key conversion

Overall this is a well-scoped, well-tested fix. The isIndexAware() override mirrors BinaryCondition's cleanly, the rangeOp terminal-detection fix for composite keys is correct and the new betweenInsideCompositeIndexStopsKeyBuildingAtTheRangeField test genuinely proves it (traced through buildIndexSearchDescriptor: rangeOp is scoped per index-field iteration and correctly breaks the outer loop after a range-shaped condition, so a later equality field can no longer be folded into the ordered key). The LSMTreeIndex.convertKeys -> convertKeysToDeclaredTypes delegation is behavior-preserving (convertKeysToDeclaredTypes handles the null array case identically to the code it replaces) and, as a side benefit, now reads the volatile mutable reference once instead of twice - a small extra safety margin against a splitIndex() swap mid-conversion, even though that wasn't the stated goal.

Finding: one more copy of the same "only BinaryCondition is understood" bug was missed

The PR fixes IndexSearchDescriptor.requiresMultipleIndexLookups() (engine/src/main/java/com/arcadedb/query/sql/executor/IndexSearchDescriptor.java:69-70) to also recognize BetweenCondition, so a matched BETWEEN no longer forces an unnecessary DistinctExecutionStep. But there's a second, near-identical private method with the same name and body shape in SelectExecutionPlanner:

// 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 createParallelIndexFetch() (SelectExecutionPlanner.java:3448), which builds the sub-plan for each branch of a query that needs multiple different indexes (e.g. WHERE a = 1 OR b BETWEEN 10 AND 20 where a and b have separate indexes). For the b branch, desc.keyCondition's single sub-block is a BetweenCondition, so this method still returns true and an extra DistinctExecutionStep gets chained onto that branch's sub-plan - exactly the class of "unnecessary DISTINCT step" the PR description says it's fixing, just in the sibling copy of the same check. Not a correctness bug (the outer executionStepFromIndexes already adds its own DistinctExecutionStep when there's more than one descriptor, so results stay correct) - just a missed, redundant step, silently untested since the new test class doesn't exercise the multi-index OR path.

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 IndexSearchDescriptor's was updated, or better, have createParallelIndexFetch call desc.requiresMultipleIndexLookups() (the now-fixed one on IndexSearchDescriptor) instead of re-implementing the check locally, removing the duplication rather than just patching both copies.

Minor / non-blocking

  • SelectExecutionPlanner.buildIndexSearchDescriptor (line ~3862): after setting rangeOp = true for a BetweenCondition, the code still enters the while (blockIterator.hasNext()) loop looking for next.createRangeWith(singleExp) to find an "additional range condition." BetweenCondition doesn't override createRangeWith (defaults to false in BooleanExpression), so this is always a no-op scan over the remaining sub-blocks when the terminal field is a BETWEEN - harmless given the small number of remaining AND terms, just worth knowing about.
  • Nice discipline keeping BetweenCondition.resolveKeyFrom/resolveKeyTo/isKeyFromIncluded/isKeyToIncluded untouched since they were already correct.

Tests

Good 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 OR path (createParallelIndexFetch) with a BETWEEN branch, which is what would have caught the finding above.

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>
@lvca

lvca commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

Addressed the code-review finding in 8f7c465:

Third duplicate copy of "only BinaryCondition is understood" - fixed by removing the duplication, not patching it. SelectExecutionPlanner had its own private requiresMultipleIndexLookups(AndBlock) (used only by createParallelIndexFetch()), separate from the one on IndexSearchDescriptor that the first commit already fixed. Rather than add the same BetweenCondition check a third time, removed SelectExecutionPlanner's copy entirely and pointed the call site at desc.requiresMultipleIndexLookups() - one implementation instead of two, consistent with the PR's own stated goal for the key-conversion half of this fix.

Also added orAcrossTwoIndexesWithBetweenBranchMergesWithoutRedundantDistinct, covering the OR-across-two-indexes-with-a-BETWEEN-branch scenario the review pointed at: asserts both indexes are used, exactly one top-level DISTINCT merges the branches (not a redundant one per branch), and the returned row set is correct.

On the reviewer's "minor/non-blocking" note about createParallelIndexFetch itself: while tracing this I confirmed that method is reached only through the polymorphic-subtype recursion (handleTypeAsTargetWithIndexRecursive, used when a base type has zero records of its own and dispatches per-subtype) - a plain OR query on a single concrete type is intercepted earlier by handleTypeAsTargetWithIndexedFunction, which already called the correct bestIndex.requiresDistinctStep() before this PR. I didn't add a test that reaches createParallelIndexFetch specifically (constructing a reliable, non-contrived repro requires a base type with zero own records plus per-subtype-resolved indexes, and the reviewer's own writeup already establishes this was never a correctness bug - just a redundant step). The fix itself removes the risk regardless of which path exercises it, since there's now only one implementation to be either right or wrong.

All 7 tests in Issue5966BetweenUsesIndexTest pass, plus the composite-index/case-insensitive-index/max-min-from-index suites and the full com.arcadedb.query.sql.executor.** package - no regressions.

@claude

claude Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review

I read through the full diff (5 source files + the new Issue5966BetweenUsesIndexTest) and traced the call paths involved. Overall this is a well-scoped, well-tested fix. Note: I was not able to run mvn verify in this sandbox (build commands require interactive approval that isn't available here), so this is a code-reading review, not a build-verified one — worth a local mvn verify -pl engine run before merge if CI hasn't already gone green.

Correctness

  • BetweenCondition.isIndexAware() mirrors BinaryCondition.isIndexAware()'s identifier/range checks correctly, and short-circuits safely (first.isBaseIdentifier() guards the getDefaultAlias() call, avoiding an NPE for non-identifier left sides).
  • The rangeOp terminal-detection fix in SelectExecutionPlanner.buildIndexSearchDescriptor() is correct: once a BetweenCondition is matched for a composite-index field, rangeOp = true stops the loop from folding a later equality field into the same ordered-range key — verified this against the betweenInsideCompositeIndexStopsKeyBuildingAtTheRangeField test logic, and the "look for the opposite range condition" block that follows is a no-op for BetweenCondition since createRangeWith() defaults to false and isn't overridden there, so no accidental ClassCastException on the (BinaryCondition) next cast.
  • IndexSearchDescriptor.requiresMultipleIndexLookups()/.cost() and FetchFromIndexStep.updateIndexStats() get symmetric BetweenCondition handling — consistent with how FetchFromIndexStep.init()/processBetweenCondition() already handled standalone BetweenCondition before this PR, so the composite-AndBlock case now matches the pre-existing single-condition case.
  • The LSMTreeIndex.convertKeys() → convertKeysToDeclaredTypes() delegation is behaviorally identical to the old inline code: same Type.convert + same-field case-insensitive fold, and snapshotting mutable into a local m before reading m.binaryKeyTypes is arguably slightly safer than the original two separate reads of the volatile mutable field.
  • Removing the third private duplicate of requiresMultipleIndexLookups() in SelectExecutionPlanner.createParallelIndexFetch() in favor of desc.requiresMultipleIndexLookups() is a correct behavior-preserving simplification — IndexSearchDescriptor.getSubBlocks() handles the AndBlock case the same way the removed method did.

Minor, non-blocking observations

  • BinaryCondition.isIndexAware() has a second branch for the CI-index optimization that matches field.toLowerCase() = 'value' style expressions (isFieldWithLowerCaseMethod). BetweenCondition.isIndexAware() doesn't mirror that branch, so WHERE LOWER(name) BETWEEN 'a' AND 'c' on a CI index won't use the index (falls back to row scan) even though the direct-column case now does (covered by betweenOnCaseInsensitiveIndexedColumnUsesIndexAndFolds). Given the PR's stated scope (Indexed BETWEEN falls back to a bucket scan; three duplicate declared-type key conversions risk drift #5966's exact repro), this is a reasonable place to stop, but might be worth a follow-up issue if that pattern shows up in practice.
  • The new test class doesn't use @Tag, which is correct here since none of the six tests are slow/benchmark-style — each is small, fixed-size data.

Test coverage

Strong. The six tests in Issue5966BetweenUsesIndexTest cover: single-column BETWEEN uses index + no row-level filter, result-set equivalence with the two-sided AND form (inclusive bounds), composite-index key truncation at the range field, NOT BETWEEN still correct via the row-scan path, case-insensitive (COLLATE CI) BETWEEN, BETWEEN as the first field of a composite UNIQUE index (exercising the insert-side convertKeys delegate), and an OR-across-two-indexes-with-a-BETWEEN-branch case asserting exactly one top-level DISTINCT. The commit history shows these were added incrementally in response to code review, which is good iterative hygiene, and the PR description confirms each assertion was verified to fail pre-fix.

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.

@lvca

lvca commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

Latest review pass found no correctness issues and confirmed the two fixes from the prior rounds. On the one minor, explicitly-optional observation - WHERE LOWER(name) BETWEEN 'a' AND 'c' on a CI index not using the isFieldWithLowerCaseMethod optimization branch BinaryCondition.isIndexAware() has: agreed this is out of scope for #5966 (whose repro is a plain indexed column, not the LOWER()-wrapped CI-index optimization), and the reviewer's own text already reaches that conclusion ("a reasonable place to stop... might be worth a follow-up issue if that pattern shows up in practice"). Not implementing it here; happy to file a follow-up issue if it comes up in practice.

Waiting on build-and-package (runs the full mvn verify) and the last Analyze job to finish before this is mergeable.

@codecov

codecov Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.22%. Comparing base (1283d66) to head (8f7c465).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...dedb/query/sql/executor/IndexSearchDescriptor.java 33.33% 1 Missing and 1 partial ⚠️
...edb/query/sql/executor/SelectExecutionPlanner.java 66.66% 1 Missing ⚠️
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.
📢 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.

@lvca

lvca commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

`ha-integration-tests` failed on this run with two test failures, both in the `ha-raft` module:

  • `Issue5410AbandonedTicketReleaseIT.abandonedEntryReleasesItsPhase2TicketOnceApplied` - `AssertionFailedError: [Node 0 must hold both vertices] expected: 2L but was: 1L` (replication-convergence timing)
  • `Issue5569SlotMergeDeleteRaftIT.mergedDeletesReplicateIntact` - `ExecutionException: AssertionError: Update returned null: record=3 seq=8` (slot-merge delete replication timing)

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.

@lvca

lvca commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

Rerun of `ha-integration-tests` failed again, but with a different specific failure profile than the first run:

  • `Issue5410AbandonedTicketReleaseIT` (again - same class as run 1)
  • `RemoteStickyConnectionStrategyIT` (new this run, run 1 instead had `Issue5569SlotMergeDeleteRaftIT` fail)

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.

@lvca

lvca commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

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.

@codacy-production

codacy-production Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 2 complexity

Metric Results
Complexity 2

View in Codacy

🟢 Coverage 80.00% diff coverage · -6.44% coverage variation

Metric Results
Coverage variation ✅ -6.44% coverage variation
Diff coverage ✅ 80.00% diff coverage

View coverage diff in Codacy

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.

@lvca

lvca commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

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:

Run Failure(s)
1 `Issue5410AbandonedTicketReleaseIT` + `Issue5569SlotMergeDeleteRaftIT`
2 `Issue5410AbandonedTicketReleaseIT` + `RemoteStickyConnectionStrategyIT`
3 `Issue5410AbandonedTicketReleaseIT` (alone)
4 `RaftPriorityRejoinIT` (alone)

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 engine, nothing in ha-raft). Combined with the earlier finding that main itself failed its last 4 CI runs (one of which also failed the unrelated unit-tests lane), this is conclusive: the CI environment is currently exhibiting broad timing-sensitive flakiness in the Raft integration suite, independent of any specific branch's changes.

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 main - worth flagging to whoever owns CI/infra if it keeps happening across other PRs too.

@lvca

lvca commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

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 main itself is independently red on this same lane right now (confirmed via its last 4 CI runs). This PR's diff never touches `ha-raft`.

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.

@lvca

lvca commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

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.

@lvca

lvca commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

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.

@lvca lvca self-assigned this Aug 10, 2026
@lvca lvca added this to the 26.9.1 milestone Aug 10, 2026
@lvca
lvca merged commit d86debf into main Aug 10, 2026
135 of 145 checks passed
@lvca
lvca deleted the fix/5966-between-index-dedup-keyconv branch August 10, 2026 05:56
lvca added a commit that referenced this pull request Aug 10, 2026
…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.
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.

1 participant