You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BETWEEN on a case-insensitive (COLLATE CI) index doesn't use the index when wrapped in LOWER() #6033
Follow-up from #5966 (fixed in #6018). #6018 taught the planner to recognize a bare field BETWEEN a AND b as index-range-eligible, including on COLLATE CI indexes:
CREATEINDEXON Product (name COLLATE CI) NOTUNIQUE;
SELECT*FROM Product WHERE name BETWEEN 'a'AND'c'-- uses the index (fixed by #6018)
However, the equivalent query with the common LOWER()-wrapped pattern still falls back to a full bucket scan:
SELECT*FROM Product WHERELOWER(name) BETWEEN 'a'AND'c'-- does NOT use the index
Root cause
BinaryCondition.isIndexAware() has two branches: one for a direct column comparison, and a second CI-index optimization that matches field.toLowerCase() = 'value'-style expressions via isFieldWithLowerCaseMethod() (see engine/src/main/java/com/arcadedb/query/sql/parser/BinaryCondition.java). BetweenCondition.isIndexAware() (added in #6018) only mirrors the first branch - it doesn't have an equivalent check for the LOWER()-wrapped case, so it falls through to the BooleanExpression default (false) and the planner picks a full scan instead.
Suggested fix
Extend BetweenCondition.isIndexAware() with a second branch analogous to BinaryCondition's, reusing isFieldWithLowerCaseMethod() (or a shared helper extracted from it) against first, gated the same way (info.isCaseInsensitive() and both bounds isEarlyCalculated).
Environment
Discovered during code review of PR #6018 (merged, commit d86debf3), which fixed #5966. Not implemented there since it's outside that issue's exact repro (a plain indexed column) - filed separately per the reviewer's own suggestion ("worth a follow-up issue if that pattern shows up in practice").
I can take this next, after #6010. I’ll add focused planner coverage for LOWER(field) BETWEEN on a COLLATE CI index, mirror the existing case-insensitive index-aware behavior, and submit it as a separate scoped change.
Reproduction found one syntax distinction worth recording: the exact SQL spelling LOWER(name) currently raises Unknown function name 'LOWER'; ArcadeDB's supported equivalent is name.toLowerCase(). The supported form reproduces the planner gap exactly (full bucket scan before the fix), and now uses the COLLATE CI range index with correct results.
I am keeping this change scoped to the planner behavior described in the root cause rather than making an otherwise-unknown SQL function work only when this particular index plan is available. A standard SQL LOWER() alias, if desired, should be implemented consistently as a separate parser/function change.
Activity
justinblethrow-cloud commentedon Aug 10, 2026
I can take this next, after #6010. I’ll add focused planner coverage for LOWER(field) BETWEEN on a COLLATE CI index, mirror the existing case-insensitive index-aware behavior, and submit it as a separate scoped change.
justinblethrow-cloud commentedon Aug 10, 2026
Reproduction found one syntax distinction worth recording: the exact SQL spelling
LOWER(name)currently raisesUnknown function name 'LOWER'; ArcadeDB's supported equivalent isname.toLowerCase(). The supported form reproduces the planner gap exactly (full bucket scan before the fix), and now uses theCOLLATE CIrange index with correct results.I am keeping this change scoped to the planner behavior described in the root cause rather than making an otherwise-unknown SQL function work only when this particular index plan is available. A standard SQL
LOWER()alias, if desired, should be implemented consistently as a separate parser/function change.review: import assertj catchThrowable and CommandExecutionException i…
test(#6033): pin the negative paths of BetweenCondition's new CI-lowe…
fix(#6033): BETWEEN on a COLLATE CI index now uses the index when wra…