Skip to content

[Performance]: FORCE INDEX range predicate reads whole index table #32129

Closed as duplicate

Description

@Ariznawlll

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 values

Measured

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 = 500 on the same index: prefix_eq block filter, 16 blocks — healthy.
  • Range in the default plan path (WHERE g>100 AND g<110 AND v>90000 ... on idx_gv): generates prefix_in_range — healthy.
  • Range via FORCE INDEX: falls back to whole-index read + per-row serial_extract filter — 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

  1. added this to the MO-202611 milestone on Nov 4, 2026
  2. added
    kind/bug
    on Nov 4, 2026
  3. added theissue type on Nov 4, 2026
  4. XuPeng-SH commented on Nov 9, 2026

    @XuPeng-SH
    Contributor

    This issue is being consolidated into #32209, which tracks the shared secondary-index first-column range-bound problem. Preserve this FORCE INDEX reproduction and its full-scan evidence as a separate acceptance case there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions