Skip to content

[Performance]: Reduce column-container append, validity-range and typed-read overhead #30175

Closed

Description

@VioletQwQ-0

Is there an existing issue for performance?

  • I have checked the existing issues.

#24097 is the broad query-execution performance umbrella. This issue tracks the four concrete column-container improvements in PR #30160. No dedicated issue for that PR was found.

Environment

Details of Performance

Existing column-container paths perform unnecessary per-row work:

  1. vector.AppendFixedList assigns each fixed-width value individually even for disjoint, all-valid batches with sufficient capacity.
  2. vector.AppendBytesList / AppendStringList repeatedly grow non-inline payload storage for fresh raw varbinary and legacy varchar vectors.
  3. Borrowed Arrow validity Nulls.CountRange / InitBorrowedWindow scan individual bits when masked boundary bytes and word population counts can preserve the same result.
  4. GetFixedAtNoTypeCheck / Vector.GetBytesAt repeat const/flat class decisions during row reads.

PR #30160 implements typed bulk copy and one-time payload reservation for the eligible append cases, word-based borrowed-validity range counting, and a single class decision in typed getters. Small, nullable, overlapping, reused/borrowed or validation-sensitive inputs retain the applicable original paths.

Representative local API benchmark medians (2048 rows/bits; ns/op, lower is better):

Scenario Before After Speedup
Fixed int64 append, no NULL, retained capacity 1373 238.45 5.76×
Fresh varbinary append, 64-byte values 175504 68542.5 2.56×
Borrowed validity range count, mixed NULL 1917 48.335 39.66×
Typed int64 read, flat 8134.5 5593.5 1.45×

Append measurements compare a53390c57d with 44e4b676fe; range/read measurements compare 44e4b676fe with 56c4323011. ABBA order, six 250 ms samples per variant/case; 59 cases and 708 samples in total. Speedups are independent and must not be multiplied. They do not establish SQL throughput or cross-version compatibility. Byte-getter benchmarks consume length and first byte rather than all content. The later head change only repairs an isolated CI test.

Compatibility and acceptance criteria

  • Preserve public signatures, NULL/metadata, overlap behavior, short-mask errors and error precedence.
  • Preserve allocation accounting, rollback, borrowed backing lifetime, getter bounds/type guards and returned byte aliases.
  • Verify serialization byte equality / round-trips and relevant boundary cases.
  • Pass complete nulls/vector/batch/aggexec/group unit tests, nulls/vector race tests, typed-read tests with typecheck, and incremental static checks locally.
  • Complete required hosted CI/BVT for the latest PR head before merge.

No on-disk or wire-format change is intended. Real SQL workload gains and cross-version node tests remain outside the measured local evidence; no such claim is made.

Additional information

Implementation and detailed validation: #30160. Related umbrella: #24097; this dedicated issue does not close the umbrella.

The PR also repairs TestAutoIDCacheRestartAndDisabledNode: each running cluster generation receives the original 3-minute SQL budget after startup, preventing restart admission from consuming the next generation's budget. Existing persistence, disabled-node rejection, ID and metadata assertions remain unchanged. A deterministic expired-context probe fails on verified main and passes with the fix; the original test, complete owning isolated package, focused adaptive race and incremental lint pass locally.

Hosted validation: MatrixOne ALL CI, attempt 2 completed successfully on ef9ba664d8a0573b9310b1d770e31e64a7a6564a, including the CI Required gate. Upgrade jobs were skipped; this is not cross-version upgrade proof. PR #30160 is ready for review; any CI triggered by the readiness event is tracked separately on the PR.

Performance regression follow-up (2026-10-15)

A focused main-to-current-head ABBA comparison (11 cases, six samples per variant/case) found a downside in fresh all-inline 8-byte values: 2048-row varbinary append takes 24843.5 -> 26402.5 ns/op (+6.28%); 128 rows are +4.73%. The pregrow path scans lengths although no non-inline payload needs reservation. The original three small varchar median slowdowns did not reproduce their previous magnitude (-1.92%, -0.82%, +0.49%). Long-value positive controls retain their gains.

  • Tighten eligibility to avoid unnecessary all-inline scanning and remeasure, or explicitly accept the measured tradeoff in review before merge.

No production code changed in this diagnostic follow-up. These local API results do not establish SQL workload regression or universal non-regression. Passing CI does not close this performance concern; see PR #30160 for the disclosure.

Owner decision (2026-10-15): retain the implementation and accept the disclosed small, local all-inline API tradeoff; no extra performance change is requested for these cases. Measurements and the SQL-workload limitation remain documented. This acceptance does not waive correctness/compatibility checks or materially different performance regressions.

Activity

  1. added a commit that references this issue on Oct 16, 2026
    7c61f67
  2. XuPeng-SH commented on Oct 16, 2026

    @XuPeng-SH
    Contributor

    转测 @Ariznawlll:#30160 的功能、race、typecheck 验证之外,已补齐关键性能路径的独立对照。

    验证提交:main 97415db10bdb3d6ffdf53ff1810a7e80bd78ee11。对照为同一提交中仅通过 Go overlay 撤回 #30160 在 vector.go、nulls.go、borrowed_validity.go 的性能改动,其他代码及基准输入保持一致;不是整个旧提交对比。撤回对照的相关功能检查通过。

    使用 control/main/main/control 顺序、每轮 3 个样本、每个样本 150ms、单 CPU 基准,以下为每侧 6 个样本的 ns/op 中位数:

    • 固定列 2048 行追加:1333.5 -> 281.85,约 4.73 倍。
    • 新建 varbinary 2048 行追加:207597 -> 98947,约 2.10 倍。
    • 8192 行 borrowed validity 区间统计:混合 NULL 7602.5 -> 170.4;全有效窗口 6906 -> 162.3,约 42.6–44.6 倍。
    • 2048 行 typed read:所测 int64 flat/const、bool、bytes area 路径约 1.30–1.54 倍。

    这些是限定输入上的本地微基准,不能外推完整 SQL/BigData 吞吐,也不关闭性能 umbrella #24097。请测试侧结合目标工作负载验收,保持 OPEN。

  3. Ariznawlll commented on Oct 20, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:官方 main
    • commit:7c146f4adbf068dd0c06b377157cfb7d7698b1eb(本轮测试时的官方 main,隔离、干净的工作树)
    • 修复:perf(container): optimize appends, validity ranges and typed reads #30160 已 MERGED,merge commit 7c61f67e5dc46b0b8e591fe957219308b078bfa4;GitHub compare 显示该提交是上述 main 的祖先(ahead 94、behind 0)。
    • 环境:macOS/arm64、Apple M3、Go 1.27.1;本轮为本地列容器 API/Go 回归与单核微基准,不是 MO 服务部署、SQL 吞吐或多 CN 性能测试。
    • 日期:2026-10-20。

    原问题验证

    本 issue 的验收对象是固定列/变长列批量追加、借用 Arrow validity 的区间统计和 typed getter 四类列容器热路径,不要求把 API 微基准外推为整条 SQL 的性能。上述修复在本轮 main 上的相应功能用例各重复 3 次均通过。以 GOMAXPROCS=1、-benchtime=200ms -count=3 -benchmem 重新测量,固定 int64 2048 行追加为 248.9/240.3/252.1 ns/op(中位数 248.9,0 alloc/op);新建 varbinary 2048 行、64-byte 值追加为 53017/50306/50357 ns/op(中位数 50357);8192 行混合 NULL 的 borrowed validity CountRange 为 103.6/118.5/104.3 ns/op(中位数 104.3,0 alloc/op)。2048 行 typed read 的 flat int64 三次为 5615/4682/4630 ns/op(中位数 4682,0 alloc/op)。

    这些是本机新测的修复版绝对值,没有拿不同机器/日期的数值直接计算加速比。修复前后同代码基底、仅回退相关性能改动的 ABBA 对照及六样本中位数已由研发在交接评论给出:固定列 1333.5→281.85、变长列 207597→98947、借用 validity 混合 NULL 7602.5→170.4 ns/op;本轮结果方向一致,但不冒充同机 A/B 或 SQL 端到端增益。

    Happy Path 覆盖

    1. pkg/container/{nulls,vector,batch} 与 pkg/sql/colexec/{aggexec,group} 五个完整 Go 包 -count=3 均 PASS;固定列和变长列结果、NULL/元数据、typed read 数值和 byte alias、借用 validity 的计数及序列化/往返用例均在其中。
    2. 定向固定列/变长列、borrowed validity、typed read 用例 -count=3 PASS;同组 -race -count=3 PASS;vector -tags typecheck -count=3 PASS。
    3. 微基准另覆盖 int64 const、bool flat、bytes inline/area 2048 行 typed read,三次均完成且 0 alloc/op。

    Unhappy Path 覆盖

    1. 短 NULL mask、输入与输出别名/增长、nullable 前缀、变长列预算不足回滚及 borrowed backing 生命周期:对应现有 Go 用例在上述完整包 -count=3 内通过;错误/边界路径未通过放宽断言来换取 PASS。
    2. owner 已披露并接受小尺寸 all-inline varbinary API 路径的局部性能取舍;本轮没有把它写成普遍无回归,也没有将其等同于 SQL 性能结论。

    白盒验证

    本轮本地完整包 3 次、定向 race 3 次、typecheck 3 次均 PASS。当前修复不改磁盘/协议格式;本轮未做跨版本节点升级测试。

    回归测试

    回归已随 #30160 合入产品仓库,覆盖 append_list_fastpath_test.go、append_varlen_pregrow_test.go、borrowed_validity_range_test.go、typed_read_test.go 及对应基准。该问题是容器内部 API/性能路径,现有 Go UT/race/基准直接覆盖原路径,按当前约定不重复增加 MOTR SQL 用例。#30160 提交前的 MatrixOne ALL CI attempt 2 已成功;另一个合并后 TKE job 在 Docker Hub 基础镜像 metadata HEAD 超时,测试前失败,不能视为产品失败或 TKE 通过。

    测试证据

    • 本轮命令:go test ./pkg/container/nulls ./pkg/container/vector ./pkg/container/batch ./pkg/sql/colexec/aggexec ./pkg/sql/colexec/group -count=3 -timeout=20m,五包均 ok;vector/nulls 定向 -race -count=3 和 vector -tags typecheck -count=3 均 ok。
    • 定向基准:GOMAXPROCS=1 go test ./pkg/container/vector ./pkg/container/nulls -run '^$' -bench 'BenchmarkAppendFixedListReuse/flat_2048$|BenchmarkAppendVarlenList/bytes_varbinary_cold_2048$|BenchmarkBorrowedValidityRange/count_mixed_8192$|BenchmarkVectorTypedRead' -benchtime=200ms -count=3 -benchmem;具体数值如上。
    • 可独立查看的产品回归文件、修复 PR、成功 CI 与研发 ABBA 对照链接如上。未执行新的 TKE、完整 SQL 性能或跨版本升级工作负载;本结论仅针对本 issue 定义的列容器 API 范围。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions