Repository navigation
Description
Environment
- MatrixOne main@HEAD (c6683bd), 3-CN local cluster
- Table:
cov8m (k INT PRIMARY KEY, g INT NOT NULL, v INT NOT NULL, KEY idx_g(g), KEY idx_gv(g,v))— 30,000,000 rows
Reproduction
SELECT COUNT(DISTINCT g) FROM cov8m FORCE INDEX(idx_g) WHERE g BETWEEN 100 AND 199;
-- 3,000,000 matching rows, 100 distinct valuesMeasured
| plan | time |
|---|---|
| default (AP full table scan + parallel GROUP BY) | 174 ms |
| FORCE INDEX(idx_g) | 2.6 - 4.3 s (3 runs: 3.2 / 2.6 / 3.1 s) |
25-40x slower with the index. Same defect on a 1M-row table: FORCE INDEX 147-200 ms vs default 37-55 ms (4x).
EXPLAIN ANALYZE evidence
-> Index Table Scan on cov8m.idx_g
inputBlocks=3663 inputRows=30000000 outputRows=3000000
ReadSize=160.78 MiB | 115.60 MiB (cache)
Filter Cond: serial_extract(__mo_index_idx_col, 0, INT)) BETWEEN 100 AND 199
The BETWEEN on the index's first column is compiled as a row-level residual filter on the serialized index column — the whole index table (all 30M entries, 3,663 blocks) is read and every entry is deserialized via serial_extract just to be filtered. It should be a prefix_in_range(__mo_index_idx_col, ...) block-level predicate + ranged index read (which the non-forced plan can generate — see below).
Asymmetry
- Equality
g = 500on the same index:prefix_eqblock filter, 16 blocks — healthy. - Range in the default plan path (
WHERE g>100 AND g<110 AND v>90000 ...onidx_gv): generatesprefix_in_range— healthy. - Range via FORCE INDEX: falls back to whole-index read + per-row
serial_extractfilter — broken.
So the two index-application code paths handle range predicates inconsistently: applyIndexJoin (apply_indices.go:4740, calls replaceRangePairCondition → prefix_in_range) vs the force/only-scan path (apply_indices.go:4154), where the serialized range folding is missing, leaving a residual row filter.
Impact
FORCE INDEX is the standard escape hatch when the planner picks a bad plan (which currently happens a lot — see covering-index issue). Using it with any range predicate makes the query catastrophically worse than no index at all — reading the entire index entry-by-entry with per-row deserialization. Users benchmarking "with index vs without" will conclude indexes make things 25-40x slower.
Suggested fix direction
Unify the range-predicate folding: in the force-index/index-only path, fold first-column range predicates on the serialized index column into prefix_in_range block filters (same as replaceRangePairCondition does), so the reader can skip to the range instead of scanning the whole index table.
Activity
XuPeng-SH commentedon Nov 9, 2026
This issue is being consolidated into #32209, which tracks the shared secondary-index first-column range-bound problem. Preserve this
FORCE INDEXreproduction and its full-scan evidence as a separate acceptance case there.