Repository navigation
Description
Scope
Track the 4.2-dev counterpart of the serialized secondary-index range-bound work from #32209.
- Original issue: [Performance]: Index range bounds degrade to opaque block filters #32209 (fixed and closed on
main) - Main fix: fix(plan): bound serialized regular-index range scans #32503, merge commit
5a5422598a7966c570f84e4f2923fc9361b359c3 - Consolidated acceptance cases: [Performance]: FORCE INDEX range predicate reads whole index table #32129 (FORCE INDEX first-column range) and [Performance]: composite index second-column range prunes nothing, constant prefix scan #32063 (equality prefix + next-column range)
Why 4.2 needs its own change
#32503 is not an ancestor of 4.2-dev (checked at 71e22339c8), and it cannot be cherry-picked: the 4.2 planner has a different regular-index access implementation. On 4.2-dev the relevant functions are:
pkg/sql/plan/apply_indices.go:applyIndexJoin->replaceNonEqualConditionfor single-sided ranges;- same file:
replaceRangePairCondition(around line 3430) for two-sidedin_range/between; indexTableLookupSerialFuncserialization plusprefix_in_range/prefix_betweenbinding.
4.2-dev has no matchRegularIndexOnlyScan family, so the main patch shape does not exist there. The 4.2 fix must be implemented against the applyIndexJoin path rather than ported verbatim.
Impact
Standard fact-join shape:
SELECT COUNT(*) FROM big8m t1 JOIN big1m t2 ON t1.k2 = t2.k2 WHERE t1.k2 < 100;Before the main fix this read roughly 20M of 30M base rows and the whole index table (inputRows=1,000,424), because serialized range bounds degraded into a block filter that pruned nothing. This is a first-class range/join access path for release-line deployments, not an edge case, so it is treated as high priority for the 4.2 line.
Acceptance criteria
- Default plan:
k2 < Non an indexed column yields a bounded index scan, withEXPLAIN ANALYZEinputBlocks/inputRows scaling with the range instead of the table/index size. - FORCE INDEX case from [Performance]: FORCE INDEX range predicate reads whole index table #32129 (30M entries): no full index-table scan and no per-row
serial_extract. - Composite case from [Performance]: composite index second-column range prunes nothing, constant prefix scan #32063:
KEY(a, b)witha = const AND b > loprunes within the leading-key prefix. - Result equality against an unindexed control table for every case.
- Boundary coverage: empty and closed intervals, NULL, duplicate values, nullable UNIQUE, VARCHAR/VARBINARY with embedded NUL, prepared statements, and restart.
- Base and fixed runs on the same 4.2 SHA and dataset, reporting both failing-base and passing-fix
EXPLAIN ANALYZEoutput. - Pruning is justified by measured inputRows/inputBlocks, not by the rendered
<opaque>literal, which is display-only.
Evidence status
- Confirmed by source inspection:
#32503and its new planner helpers (matchRegularIndexSuffixRange,regularIndexRangeFunctionsUsableAtPart,replaceCompositeRangeCondition) are absent from4.2-dev. - Not yet captured: a 4.2.8 or 4.2-dev runtime
EXPLAIN ANALYZEmeasurement. An attempt to start an isolated v4.2.8 cluster locally did not reach a usable state, so base measurements on the 4.2 line remain outstanding and are part of the acceptance work. - Do not close this issue based on the main fix or main CI; 4.2 evidence is separate.
Activity
XuPeng-SH commentedon Nov 19, 2026
Tracked in the active 4.2 follow-up tracker #32896 under "2. Confirmed 4.2 performance follow-ups" as a high-priority item (marker
mo-42-followup-20261119:32928).The older backport review list #32157 covers main merges up to 2026-11-04 only and is not modified.
[4.2-dev] fix(plan): bound covering index range scans (#32930)
XuPeng-SH commentedon Nov 20, 2026
转 QA 验证,不代表验收通过。#32930 已于 2026-11-20 11:38:03 UTC 合入 4.2-dev,merge SHA
1aa4d1ab96fbc40f2752bdf9dcb335b8436b3e03,最终 head8bf856a8b371bf4b144ec118723aa121a998cafe。本次在 release 分支相应 covering scan owner 建立序列化范围边界,并组合兼容的相向端点,涵盖 leading range、equality prefix 后 next-column range 与 index backfill。保留 SQL 精确复核、既有更窄边界,以及不支持/可能抛错表达式和无效 flags 的 fallback;动态或非整数表达式及 prepared 场景仍按适用条件保守回退,不承诺所有参数化查询都新增裁剪。
作者报告同一持久化 3,000 万条索引数据上,强制 COUNT(DISTINCT) 范围结果修复前后均为 100,索引输入由 3,720 blocks / 3,000 万 rows 降至 480 blocks / 300 万 rows。这是单 CN 扫描工作量对照,不是延迟基准,也不能写成精确只扫描 100 行。另报告完整 plan 普通/race 单测、增量格式/vet/lint、58/58 SQL、covering/noncovering paired range 持久化重放、四个阈值 default JOIN 及 72 个 indexed/unindexed 边界对照通过。本轮仅远端核对,未运行本地测试或审计原始日志。
当前完整 issue 评论未见新修复后的已验证反例或未完成开发 follow-up。请 QA 固定包含 merge 的 4.2 版本,按原 default JOIN、FORCE INDEX、复合前缀场景核对 EXPLAIN ANALYZE inputBlocks/inputRows 和结果一致性;覆盖空/开闭区间、NULL/重复值、nullable UNIQUE、含 NUL 字符串、prepared 复用与 restart。作者摘要未独立证明全部重启/原部署边界,应据实际测试补齐;不能用 main 证据或 opaque 显示代替 release 裁剪数据。
移除研发负责人,改派唯一 Ariznawlll;保持 open,不自动扩展到其他分支或部署。
Ariznawlll commentedon Nov 22, 2026
阶段性测试结论
4.2-dev 上已完成独立的 3000 万行修复前后工作量对照,范围裁剪改善明显,已测结果一致;本 Issue 仍保持开放,尚未完成对应 big-data 定期回归接入及原始部署/完整验收。
测试环境与证据
1ca6856f4f45c03ee6cb8e472764e967da725fea;修复后为官方 4.2-dev6c05e42f9f660a207077b050b8ec285ccf3f8103。运行时git_version()已核对。metadata_scan核对持久化行数;这不是复制同一物理数据目录,也不是完整延迟基准。COUNT(DISTINCT a)的a BETWEEN 5 AND 6与无索引对照结果一致;EXPLAIN ANALYZE的索引输入从修复前 3710 blocks / 3000 万行降至修复后 3 blocks / 2 万行。KEY(a,b)上a=5 AND b>=100 AND b<200,结果 100 行且与无索引表一致;索引输入由 2 blocks / 9999 行降至 1 block / 100 行。尚未完成
EXPLAIN ANALYZE时间宣称延迟改善百分比,也不视为全部专项验收通过。Ariznawlll commentedon Nov 22, 2026
补充回归进展:MOTR PR #377 已加入 4.2-dev 专用的 3000 万行持久化裁剪用例和每日 workflow。修复后版本本地通过 MOTR 1/1、无跳过;修复前版本用相同用例确认扫描量断言失败,证明用例能够检出原问题。PR CI 仍在执行;每日定时任务需 PR 合入默认分支后才会实际调度。Issue 暂时保持开放,等待 CI 及剩余验收边界。
Ariznawlll commentedon Nov 22, 2026
验收结论
通过:4.2-dev 的序列化二级索引范围裁剪已完成大数据、修复前后、重启和回归验证。 本次结论针对本 Issue 的扫描工作量及结果正确性,不代表原生产环境延迟 SLA 或多 CN 性能已单独验收。
测试环境
1ca6856f4f45c03ee6cb8e472764e967da725fea。6c05e42f9f660a207077b050b8ec285ccf3f8103;本地实例与 GitHub CI 均核对运行版本。metadata_scan确认 3000 万行已持久化;数据内容相同,物理数据目录各自独立。关键测试与结果
COUNT(DISTINCT a)范围查询,结果相同;EXPLAIN ANALYZE显示修复前读取 3710 blocks / 3000 万行,修复后读取 3 blocks / 2 万行。复合(a,b)前缀范围由 2 blocks / 9999 行降至 1 block / 100 行,结果均为 100 行。这是扫描量对照,不将单次执行时间换算为延迟提升。回归调度与边界
PR 中已配置 4.2-dev 每日专用任务。PR 尚未合入;合入默认分支后定时调度才生效,首次定时运行尚未发生。 本轮未复测原生产部署的数据分布、隔离硬件或多 CN 延迟,因此不声称已验证这些环境的性能指标。
回归更新:原 MOTR PR #377 的内容已汇总至 MOTR PR #374,原 PR 已关闭;原运行链接仅作为历史测试证据,汇总 PR 的 CI 以其当前检查为准。