Skip to content

[4.2-dev][Performance] Serialized secondary-index range bounds do not prune blocks (backport of #32209) #32928

Closed

Description

@XuPeng-SH

Scope

Track the 4.2-dev counterpart of the serialized secondary-index range-bound work from #32209.

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 -> replaceNonEqualCondition for single-sided ranges;
  • same file: replaceRangePairCondition (around line 3430) for two-sided in_range / between;
  • indexTableLookupSerialFunc serialization plus prefix_in_range / prefix_between binding.

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 < N on an indexed column yields a bounded index scan, with EXPLAIN ANALYZE inputBlocks/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) with a = const AND b > lo prunes 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 ANALYZE output.
  • Pruning is justified by measured inputRows/inputBlocks, not by the rendered <opaque> literal, which is display-only.

Evidence status

  • Confirmed by source inspection: #32503 and its new planner helpers (matchRegularIndexSuffixRange, regularIndexRangeFunctionsUsableAtPart, replaceCompositeRangeCondition) are absent from 4.2-dev.
  • Not yet captured: a 4.2.8 or 4.2-dev runtime EXPLAIN ANALYZE measurement. 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

  1. added
    kind/bug
    severity/s1
    on Nov 19, 2026
  2. XuPeng-SH commented on Nov 19, 2026

    @XuPeng-SH
    ContributorAuthor

    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.

  3. self-assigned this
    on Nov 19, 2026
  4. added
    severity/s0
    and removed
    severity/s1
    on Nov 19, 2026
  5. added a commit that references this issue on Nov 20, 2026
    1aa4d1a
  6. XuPeng-SH commented on Nov 20, 2026

    @XuPeng-SH
    ContributorAuthor

    转 QA 验证,不代表验收通过。#32930 已于 2026-11-20 11:38:03 UTC 合入 4.2-dev,merge SHA 1aa4d1ab96fbc40f2752bdf9dcb335b8436b3e03,最终 head 8bf856a8b371bf4b144ec118723aa121a998cafe。

    本次在 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,不自动扩展到其他分支或部署。

  7. Ariznawlll commented on Nov 22, 2026

    @Ariznawlll
    Collaborator

    阶段性测试结论

    4.2-dev 上已完成独立的 3000 万行修复前后工作量对照,范围裁剪改善明显,已测结果一致;本 Issue 仍保持开放,尚未完成对应 big-data 定期回归接入及原始部署/完整验收。

    测试环境与证据

    • 本地隔离单机实例:修复前为 [4.2-dev] fix(plan): bound covering index range scans #32930 合入提交的父提交 1ca6856f4f45c03ee6cb8e472764e967da725fea;修复后为官方 4.2-dev 6c05e42f9f660a207077b050b8ec285ccf3f8103。运行时 git_version() 已核对。
    • 两版本分别用同一脚本、同一建表和数据生成逻辑构造 3000 万行,均执行 flush,并通过 metadata_scan 核对持久化行数;这不是复制同一物理数据目录,也不是完整延迟基准。
    • FORCE INDEX / Happy: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 行。
    • **默认 JOIN:**在过滤阈值 1、5、20、100 下,修复前后结果均与无索引表相同;前三个阈值使用索引,阈值 100 使用基础表扫描并带 block filter。该数据分布下不能声称所有阈值都走索引,也不能把这组 JOIN 结果当作原始部署性能基准。
    • **边界 / Unhappy:**空范围、NULL、重复值、nullable UNIQUE、含 NUL 的二进制值、prepared 复用已在较小数据集上与无索引表对照;另在 100 万行数据 flush 后重启 MO,三组结果仍一致,复合索引读取 8 blocks / 100 行。

    尚未完成

    • 将足够规模的场景接入实际 4.2-dev big-data 回归并确认周期执行;以上是本地独立验收数据,并非已接入每日任务。
    • 对照原 Issue 的 JOIN 数据分布、实际部署环境和性能基准进一步验证;当前不根据单次 EXPLAIN ANALYZE 时间宣称延迟改善百分比,也不视为全部专项验收通过。
  8. Ariznawlll commented on Nov 22, 2026

    @Ariznawlll
    Collaborator

    补充回归进展:MOTR PR #377 已加入 4.2-dev 专用的 3000 万行持久化裁剪用例和每日 workflow。修复后版本本地通过 MOTR 1/1、无跳过;修复前版本用相同用例确认扫描量断言失败,证明用例能够检出原问题。PR CI 仍在执行;每日定时任务需 PR 合入默认分支后才会实际调度。Issue 暂时保持开放,等待 CI 及剩余验收边界。

  9. Ariznawlll commented on Nov 22, 2026

    @Ariznawlll
    Collaborator

    验收结论

    通过:4.2-dev 的序列化二级索引范围裁剪已完成大数据、修复前后、重启和回归验证。 本次结论针对本 Issue 的扫描工作量及结果正确性,不代表原生产环境延迟 SLA 或多 CN 性能已单独验收。

    测试环境

    • 修复前:[4.2-dev] fix(plan): bound covering index range scans #32930 合入提交的父提交 1ca6856f4f45c03ee6cb8e472764e967da725fea。
    • 修复后:官方 4.2-dev 6c05e42f9f660a207077b050b8ec285ccf3f8103;本地实例与 GitHub CI 均核对运行版本。
    • 两版本分别按相同脚本生成 3000 万行索引表和无索引对照表,flush 后用 metadata_scan 确认 3000 万行已持久化;数据内容相同,物理数据目录各自独立。

    关键测试与结果

    • **黑盒 / Happy:**单列和复合索引的范围查询与无索引表结果一致。3000 万行表与持久化 100 万行表做默认 JOIN,4 个范围阈值均与无索引对照一致。
    • **黑盒 / Unhappy:**空范围、NULL、重复值、nullable UNIQUE、包含 NUL 的二进制值及 prepared 复用在小数据集上通过对照,未发现错误结果。
    • **白盒 / 大数据性能:**强制单列索引 COUNT(DISTINCT a) 范围查询,结果相同;EXPLAIN ANALYZE 显示修复前读取 3710 blocks / 3000 万行,修复后读取 3 blocks / 2 万行。复合 (a,b) 前缀范围由 2 blocks / 9999 行降至 1 block / 100 行,结果均为 100 行。这是扫描量对照,不将单次执行时间换算为延迟提升。
    • **重启:**重启 4.2-dev MO 后,两个 3000 万行表及 100 万行 JOIN 表的持久化行数正确,查询结果仍与无索引对照一致;单列和复合索引分别读取 3 blocks / 2 万行、1 block / 100 行。
    • MOTR:PR #377 新增 4.2-dev 3000 万行回归,含默认 JOIN 和两个索引扫描量上界。相同用例在修复前能检出扫描超限,修复后本地通过;GitHub CI run 45053415030 实际执行 1/1 通过、0 失败、0 跳过,离线检查也通过。

    回归调度与边界

    PR 中已配置 4.2-dev 每日专用任务。PR 尚未合入;合入默认分支后定时调度才生效,首次定时运行尚未发生。 本轮未复测原生产部署的数据分布、隔离硬件或多 CN 延迟,因此不声称已验证这些环境的性能指标。

    回归更新:原 MOTR PR #377 的内容已汇总至 MOTR PR #374,原 PR 已关闭;原运行链接仅作为历史测试证据,汇总 PR 的 CI 以其当前检查为准。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions