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
[Bug]: Prefix indexes under-fetch FORCE INDEX BETWEEN ranges #26841
CREATEDATABASEprefix_range_repro;
USE prefix_range_repro;
CREATETABLEt (
id INTPRIMARY KEY,
s VARCHAR(32),
KEY idx_s(s(3))
);
INSERT INTO t VALUES
(1, 'abcX'),
(2, 'abcY'),
(3, 'abdA'),
(4, 'abbZ');
SELECT GROUP_CONCAT(id ORDER BY id)
FROM t FORCE INDEX(idx_s)
WHERE s BETWEEN 'abcX'AND'abdA';
-- actual: 3SELECT GROUP_CONCAT(id ORDER BY id)
FROM t IGNORE INDEX(idx_s)
WHERE s BETWEEN 'abcX'AND'abdA';
-- expected: 1,2,3
The same result was reproduced on current main (45a917d7f8) and on PR #26829 (b1cd7bb3e1), so this is pre-existing and is not caused by that PR.
Expected behavior
A declared prefix index is a lossy candidate structure. FORCE INDEX may change the access path, but it must not change the SQL result. Every row whose full value is in the requested range must remain a candidate and be rechecked against the base-table predicate.
Actual behavior and likely boundary
The hidden table stores substring(s, 1, 3). The range rewrite compares that truncated key against the untruncated BETWEEN bounds and then does not retain the leading BETWEEN predicate as a base-table residual. Values abcX and abcY are excluded before the base table can recheck them.
A safe fix is to avoid range/BETWEEN index rewrites for declared prefix parts, or derive a conservative candidate condition and retain the original base-table range predicate.
Although this issue is already closed, I independently verified its fix on the exact #26829 merge commit ac339444b558daf2c3d7fe63f755743449db7696.
The original 08770e1 baseline under-fetched through FORCE INDEX (BETWEEN returned only id 3 while IGNORE returned ids 1,2,3). On the merge commit, FORCE equals IGNORE for BETWEEN, IN, single/paired ranges, strict bounds, OR, prepared runtime bounds, unique prefix indexes, scoped ORDER/GROUP hints, rename plus DML, and post-flush persisted blocks. EXPLAIN confirms lossy declared-prefix range paths fall back to a base-table scan, while a complete-index control remains eligible.
The later #26852 PR adds regression coverage; the production correctness fix is present in #26829.
Conclusion: confirmed fixed; keeping the existing closed state.
Activity
test(plan): cover prefix-index range correctness (#26852)
LeftHandCold commentedon Aug 11, 2026
Post-merge validation result.
Although this issue is already closed, I independently verified its fix on the exact #26829 merge commit
ac339444b558daf2c3d7fe63f755743449db7696.The original
08770e1baseline under-fetched through FORCE INDEX (BETWEEN returned only id 3 while IGNORE returned ids 1,2,3). On the merge commit, FORCE equals IGNORE for BETWEEN, IN, single/paired ranges, strict bounds, OR, prepared runtime bounds, unique prefix indexes, scoped ORDER/GROUP hints, rename plus DML, and post-flush persisted blocks. EXPLAIN confirms lossy declared-prefix range paths fall back to a base-table scan, while a complete-index control remains eligible.The later #26852 PR adds regression coverage; the production correctness fix is present in #26829.
Conclusion: confirmed fixed; keeping the existing closed state.
test(plan): cover prefix-index range correctness (matrixorigin#26852)
test(plan): cover prefix-index range correctness (matrixorigin#26852)
test(plan): cover prefix-index range correctness (matrixorigin#26852)