Skip to content

perf(sql): compact physical plan metadata - #2772

Open
hnwyllmm wants to merge 7 commits into
oceanbase:masterfrom
wangyunlai-seekdb:perf/compact-physical-plan-metadata
Open

hnwyllmm wants to merge 7 commits into
oceanbase:masterfrom
wangyunlai-seekdb:perf/compact-physical-plan-metadata

Conversation

@hnwyllmm

@hnwyllmm hnwyllmm commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

任务描述

减少缓存物理计划和普通 SQL 执行对象的固定内存。计划及运行期对象原先内嵌统计、诊断、分区等数据,编译时还有部分临时分配会跟随计划存活。

解决方案

  • 精简计划统计、诊断和算子统计。按需构造子类型上下文、临时表名、DAS 范围图、分区表达式、触发器及动态列名上下文。
  • 按实际数量构造表访问项。缓存复用表访问定义和计划键,PlanSet 内联两个参数。将结构化参数元数据移到编译请求。
  • 按需分配聚合附属数据和更新映射。普通列转换省去编译期常量节点。临时 raw 表达式及外键遍历状态跟随编译请求释放。
  • 缩减执行上下文、结果集、DAS 迭代器、DML 会话备份和扫描范围等对象。沿用当前 master 的 PX 序列化字段。

验证

Linux x86-64 上 master 和当前提交的 //src/observer:seekdb 均构建、链接通过。git diff --check 通过。当前提交的 GitHub SeekDB CI 通过 300/300 个 SQLTest。GIS 缓存用例按 SQL 文本排序,继续校验执行次数、命中次数和 SQL 文本。

整份缓存执行计划内存

在同一 Linux x86-64 隔离环境对比本 PR 的 master 基线 d8dec2590bc0 与当前提交 c1d44182053a。两边均使用 O2 构建和 sysbench 1.0.20,单线程、每表 2,500 行。每边采到 63 份实际执行的预处理计划,共执行 2,232 条读写 SQL。两边逐条匹配 SQL、算子树和执行次数,均为零忽略错误和零重连。

表中每行按该场景的独立计划取平均。已用和持有均来自整份物理计划的 arena,分别表示分配所用字节和分配器持有的页容量。

sysbench 场景 计划数 整份计划已用 KiB(master → PR) 整份计划持有 KiB(master → PR) 持有变化
主键点查 1 41.12 → 10.04 47.16 → 15.50 -67.1%
范围读 4 43.26 → 11.71 49.09 → 15.50 -68.4%
只读 5 42.82 → 11.38 48.71 → 15.50 -68.2%
只写 4 50.18 → 18.83 56.84 → 25.19 -55.7%
读写混合 9 46.09 → 14.70 52.32 → 19.81 -62.1%
四表读写混合 36 46.10 → 14.70 52.32 → 19.81 -62.1%
无二级索引只写 4 48.35 → 17.13 56.84 → 21.31 -62.5%

63 份计划合计持有容量从 3,296.28 KiB 降至 1,232.25 KiB(−62.6%)。算子树一致,计划内的部分执行表达式减少。读写混合场景中的 INSERT 从 40 个表达式降至 20 个,其整计划持有容量从 47.16 KiB 降至 23.25 KiB。

seekdb_test

当前提交 c1d44182053a 的 Linux 定向回归通过,13 个 SQL 用例及 3 项回归任务全部通过。当前结果覆盖所选回归范围。

性能回归

在同一 Linux 节点以相同 sysbench 配置,对 master d8dec2590bc0 与 PR c1d44182053a 各做一轮。六个场景均完成,忽略错误和重连为零。

场景 PR 相对 master 的 TPS 变化 P99 变化
主键点查 +3.94% −1.77%
只读 +2.57% −1.78%
读写混合 +0.10% +11.41%
插入 −0.39% +1.81%
更新非索引列 −0.11% +11.44%
只写 +1.38% −1.78%

读写混合和更新非索引列在六个 10 秒区间中均观察到更高的秒级 P99 中位数。当前只有一对独立构建,尾延迟变化的可重复性和原因待确认。

影响范围

单机 SeekDB 的物理计划生成、缓存与执行,以及同版本 PX 编解码。构建验证覆盖 Linux x86-64。

合入理由

减少普通计划与执行对象的固定占用,让诊断、分区、排序、会话备份等内存随使用路径分配。

@hnwyllmm
hnwyllmm marked this pull request as ready for review November 30, 2026 02:15
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-01T13:34:16.326076Z
We couldn’t complete this review. Comment @codex review to try again.
fb6fc71 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sort cache records by SQL text so plan size changes do not reorder the expected rows. Preserve the execution counts, cache hits, and SQL text checks.
Keep less memory in the plan arena for ordinary cached SQL.
Share immutable metadata, compact plan-owned arrays, and allocate
optional scan, DML, and expression metadata only where needed.

Built and verified 21 SQL cases and sampled 17 cached plans on the
previous master base. Rebased the same patch onto current master
and verified patch equivalence and git diff --check.
@wangyunlai-seekdb
wangyunlai-seekdb force-pushed the perf/compact-physical-plan-metadata branch from c1d4418 to 40bb7a6 Compare December 1, 2026 12:13
Reduce cached plan allocations for ordinary queries by compacting ObExpr,
moving serialization marks to partial frames, and allocating constant frames,
special parameter fields, and partition-wise join constraints only when used.

Verified a full SeekDB build and checked the compiled layouts of ObExpr,
ObExprFrameInfo, and ObPhysicalPlan. Checked the diff for whitespace errors.
Keep CHECK, foreign key and view checks in ConstraintChecks, and retain
specialized index fields only in schemas that have values for them.
Preserve the existing encoded field order and the default values.

Built the affected SQL code generation, SQL DML and storage targets,
checked serialization ordering, and verified the object sizes with DWARF.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants