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_gv(g, v), KEY idx_g(g))— 30,000,000 rows
Reproduction
SELECT k, g, v FROM cov8m WHERE g = 997 AND v < 50;This query needs exactly (g, v, k) — all of which live in the idx_gv index table (non-unique secondary indexes are physically stored as (serialized_key, pk)). Nothing should touch the base table.
Measured
| plan | blocks read | time |
|---|---|---|
| default | 500 (whole base table) | 805 ms / 191 ms |
FORCE INDEX (idx_gv) — pure Index Table Scan |
4 | 57-72 ms |
10-14x on a small-result-set query; and it gets worse with table size because the default plan is O(table), not O(matches).
The default plan is always:
Project
-> Join: INDEX join (cov8m.k = __mo_index_pri_col), [ForceOneCN]
-> Table Scan on jumpstats.cov8m (cost=4096000, 500 blocks — driver!)
-> Index Table Scan on cov8m.idx_gv
even when the SELECT list is just the PK (SELECT k FROM cov8m WHERE g=500 AND v<20000 — the PK is literally the index table's second column).
Root cause (code)
pkg/sql/plan/apply_indices.go:
:3973indexCoversRequiredColumnscomputes coverage only fromidxDef.Parts— each part column is marked incoveredCols; the physical primary key is never added to the coverage set.:3429-3439requiredCols= all columns referenced above the scan ∪ filter columns. ForSELECT k ... WHERE g=... AND v<..., required = {k, g, v}. Sincek(the PK) is never marked covered,matchRegularIndexOnlyScan(:4019) returns false and the index-only path is rejected → the planner falls back to the scan-driven INDEX join.- Contradiction inside the same file:
resolveRegularIndexBackfillResidualAccess(:3240-3245) explicitly supports reading the physical PK from the index table (regularIndexResidualPhysicalPK). The executor knows the index table always carries the PK; the planner's coverage check does not.
DML impact (same defect)
DELETE FROM cov8m WHERE g = 500 AND v < 500 (deletes ~240 rows): base table full scan (500 blocks, ForceOneCN) driving the INDEX join, plus two more INNER joins to the secondary index tables for index maintenance — 549 ms for a tiny delete. DELETE cost is O(table), not O(matched rows).
Expected behavior
When the required columns are all in idxDef.Parts ∪ {PK}, choose an index-only scan (pure Index Table Scan) instead of the base-scan-driven join-back. FORCE INDEX proves the path exists and is 10-14x faster.
Related
#32015 (join-back family) — same family, different root: this is the missing covering-column detection (parts ∪ PK), not the join-back structure itself.
Activity
fix(plan): price backfill filter setup when ranking regular indexes (#…
XuPeng-SH commentedon Nov 30, 2026
补充 #33501 合入版验证:在
main@0c5cf1775518e7974564eeb54b2157e5abc13aa6上,5 组定向 planner 用例各 3 次通过(GOMAXPROCS=16),覆盖索引创建顺序、窄覆盖/宽键回表、点查/范围及 LIKE + IN 控制。真实 MySQL TCP 的TestLikePrefixIndex和大小写不敏感对照也通过(12.388 秒)。这证明本次 SELECT 计划选择的定向行为,不是工单原始 3,000 万行的性能 A/B;该 PR 没有解决 DELETE 的基础行 ID 路径,完整 CI 也未通过。保留当前研发负责人,不转测。