Repository navigation
Closed
Labels
ai-easyAI直接干,人扫一眼就行kind/bugSomething isn't workingseverity/s0Active / top priority for current sprint. Owner has committed to working on it now.
Milestone
Description
Environment
- MatrixOne main@HEAD (c6683bd), 3-CN local cluster
big8m (k INT PRIMARY KEY, k2 INT, KEY idx_k2(k2))— 30,000,000 rows;big1msimilarly indexed (1M rows)
Reproduction
SELECT COUNT(*)
FROM big8m t1 JOIN big1m t2 ON t1.k2 = t2.k2
WHERE t1.k2 < 100;EXPLAIN ANALYZE on the default plan:
-> Join (INNER) Join Cond: serial_extract(...) = t1.k2
inputRows=2,101,000 outputRows=2,001,000,000 waitTime=819ms
-> Table Scan on big8m
inputBlocks=2452 inputRows=20,086,784 outputRows=2,001,000
Filter Cond: (t1.k2 < 100)
Block Filter Cond: (t1.k2 < 100) ← pruned only ~1/3; 20M of 30M rows read
-> Index Table Scan on big8m.idx_k2 ← used for join-back
inputRows=1,000,424 ← THE WHOLE INDEX TABLE
Block Filter Cond: (__mo_index_idx_col < '<opaque>')
-> Index Table Scan on big1m.idx_k2
inputRows=100,000 Filter: serial_extract(...) < 100 (row-level residual)
Three compounding defects:
- Range bounds degrade to
<opaque>block filters. The serialized range bound fork2 < 100fails to fold into a usable block-filter condition — the display shows'<opaque>'and block pruning on the base scan barely works (20M of 30M rows read for a predicate selecting 2M). This is the default (non-forced) plan. - Index-table scans read the entire index and filter by per-row
serial_extractresidual — the equality path generates healthyprefix_eqfilters, the range path does not fold intoprefix_in_rangehere (asymmetric withapplyIndexJoin'sreplaceRangePairCondition, which does fold ranges — see also the FORCE INDEX variant of this bug, [Performance]: FORCE INDEX range predicate reads whole index table #32129). - The join then evaluates
serial_extract(...)per row to compare keys — 2.1M inputs producing 2 billion outputs at 819-1447 ms of wait.
Impact
Time-window / bucketed-key joins with any range predicate are the standard fact-join shape. With correct bound serialization + prefix range folding + block pruning, this query reads a few thousand blocks instead of ~4,700; 0.5 s+ plan instead of multi-second wall time dominated by ~2 GB of decode work.
Suggested fix direction
- Fold first-column range predicates on secondary indexes into
prefix_in_rangeblock filters on the serialized key (same mechanismreplaceRangePairConditionalready emits). - Fix serialized-bound block filters that currently emit
'<opaque>'and prune nothing. - Consider comparing serial keys directly in the join instead of
serial_extractper row per side.
Metadata
Metadata
Assignees
Labels
ai-easyAI直接干,人扫一眼就行kind/bugSomething isn't workingseverity/s0Active / top priority for current sprint. Owner has committed to working on it now.
Activity
XuPeng-SH commentedon Nov 9, 2026
Consolidating #32129 here: both expose missing
prefix_in_rangeconversion for secondary-index first-column range predicates. Keep #32129’sFORCE INDEX(idx_g)case (30M entries; full index-table scan and per-rowserial_extract) as a distinct acceptance case alongside #32209’s default range/join path. Verify both paths produce safe, selective range bounds. #32063 concerns a range on the second column of a composite index and remains separate.XuPeng-SH commentedon Nov 9, 2026
Consolidating #32063 here as the composite-index range-bound case of the same serialized-key pruning work. Preserve separate acceptance cases for (1) a range on the first indexed column, including the FORCE INDEX path, and (2) equality on a leading column followed by a range on the next column. The compound-range case must retain exact result semantics and avoid scanning the whole leading-key prefix.
gouhongshen commentedon Nov 10, 2026
PR #32503 is trying to fix this issue.
fix(plan): bound serialized regular-index range scans (#32503)
gouhongshen commentedon Nov 11, 2026
PR #32503 has merged and is awaiting manual validation. The issue remains open.
XuPeng-SH commentedon Nov 11, 2026
转 QA 验证。PR #32503 已合入 main,merge SHA
5a5422598a7966c570f84e4f2923fc9361b359c3。请保留本项整合的 #32129 FORCE INDEX 首列范围及 #32063 等值前缀 + 后续列范围作为独立验收用例。修复提供序列化范围边界及精确行侧残余检查,保留 NULL 唯一索引完整性、字符串/二进制边界及错误求值顺序保护。旧 head
1778721a的 throwing suffix 反例已在9103f5188a修复,后续评审报告对应 base/candidate SQL 和 planner 控制通过。已重读完整 issue 评论及 PR 评审,未见适用于合并修复的已验证反例或未完成开发 follow-up。已有证据(作者/评审报告,非本轮实测):作者报告完整 planner 包通过,BVT 两轮均 111/111;评审报告 11 个 planner 测试和 memory/persisted SQL 控制通过,同一复合范围扫描从 base 4 blocks/7 rows 减至候选 2 blocks/4 rows且结果一致。最终 head 的 Ubuntu UT 曾在 TestViewDescriptionSubscription 失败,已单独记录 #32424;不能把该记录当作本轮全 CI 通过。
待 QA:在合并版本覆盖默认 range/join、FORCE INDEX 有界 COUNT(DISTINCT)、复合等值前缀后范围,并比较未索引基准的结果和扫描工作量;覆盖空/闭区间、NULL、重复值、nullable unique、VARCHAR/VARBINARY 含 NUL 边界、throwing bound 短路、回滚/重连和多 CN。原 30M 行三 CN 延迟基准未重跑,不承诺普遍耗时改善。
<opaque>是保留的字面量隐藏,默认 join 仍使用serial_extract,二者不应单凭显示形态判定范围修复失败。本轮未运行本地测试;转测不代表验收通过。Ariznawlll commentedon Nov 16, 2026
测试版本
8e8708a8d306a69512d140b40bfcfebc1d404a32(git_version()=8e8708a8d3);修复 PR fix(plan): bound serialized regular-index range scans #32503 merge SHA5a5422598a7966c570f84e4f2923fc9361b359c3已确认在该 main 祖先链。原问题验证
对
k2<3(10% 选择性)的二级索引范围:Index Table Scan on big8m.idx_k2实际只读 1 block / 3000 行(全表 4 blocks / 30000 行),k2<30全范围对照读满 30000 行——序列化范围边界已正确折叠进 block filter 并精确裁剪。big8m t1 JOIN big1m t2 ON t1.k2=t2.k2 WHERE t1.k2<3:两侧索引扫描各只读 3000 行(修复前读整张索引表),结果 3000000 与无索引控制表完全一致。__mo_index_idx_col < '<opaque>'是序列化字节串的显示渲染,不代表边界失效;实际裁剪以上述 inputRows/inputBlocks 实测为准。Happy Path 覆盖
KEY(a,b)上a=9 AND b>90:Block Filter 折叠为prefix_in_range(__mo_index_idx_col)([Performance]: composite index second-column range prunes nothing, constant prefix scan #32063 核心修复点),>=、<、<=、BETWEEN、开区间 5 个变体结果与无索引控制表逐行一致。COUNT(DISTINCT k2) ... FORCE INDEX走有界索引扫描,不再退化到全 covering index 扫描(修复的 hinted covering fallback 问题)。Unhappy Path 覆盖
a=99 AND b>90返回空集且不报 20203(filter-stability 护栏保留)。白盒验证
核对 #32503 修改范围:
pkg/sql/plan/apply_indices.go序列化范围游标边界 + 精确行侧残余检查,保留 NULL 唯一索引完整性、字符串/二进制边界及错误求值顺序保护。上游apply_indices_test.go新增 416 行;composite_index_rangeBVT(165 行 SQL)覆盖同族场景。Go 单测
TestRegularIndexCompositeSuffixRangeBounds、TestRegularIndexUniqueSuffixRangeRequiresCompleteRowSource(pkg/sql/plan)ok;焦点-race通过。回归测试
已追加 matrixorigin/motr#349:
14_issue_regression/issue_32209_index_range_bounds(Python 场景,18 项断言),覆盖首列范围裁剪实测、join 两侧有界、复合 prefix_in_range、5 个范围变体对照、空前缀护栏、NULL 排除、COUNT(DISTINCT) 有界。录制后普通 diff 模式 3 并发连续多轮通过;PR 4 项 CI 全部成功。用例标记@target-branch: main(修复未 backport 4.2-dev)。验证边界
本地为 30k/10k 行缩比数据(模式等价,block 裁剪可观测);未重复 issue 的 30M 行 / 3-CN 规模与 EXPLAIN ANALYZE waitTime 对比。多 CN 下序列化边界一致性未在本次范围。
测试结论
测试通过,关闭本 issue。