Skip to content

fix(load): restore sampling context and make CN PK checks opt-in - #30697

Merged
mergify[bot] merged 4 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/issue-30613-load-sample-context
Oct 22, 2026
Merged

mergify[bot] merged 4 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/issue-30613-load-sample-context

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #30613 (LOAD regression after #30519).

What this PR does / why we need it:

Restore authorized first-line sampling for modern LOAD, and add an explicit session policy for the CN primary-key validation enabled by #30421. The default is intentionally OFF to recover the historical bulk-load behavior. Disabling validation changes correctness semantics; it is not a speedup under equivalent checking.

  1. Bind the statement identity with process.SQLFileAccessContext before sampling. Previously the unbound context failed file admission and silently fell back to declared column widths. A BLOB column could make millions of short rows look like a small TP query and reduce reader/CN parallelism. Admission, the sample bound, fallback, and scheduling rules remain unchanged.

  2. Add dynamic SESSION BOOL mo_pk_check_by_cn, default OFF. Both modern and legacy LOAD planners use the session value. OFF omits ordinary LOAD's CN primary-key hash validation; ON retains its current eligible input/target duplicate checks, error 1062, and statement rollback. INSERT checks, index maintenance, foreign keys, and mo_pk_check_by_dn remain independently governed. Existing IGNORE/REPLACE and other validation exemptions remain.

  3. Reuse session plan invalidation after a changed SET. Other sessions and equivalent/invalid SETs preserve their state. Existing correctness tests explicitly enable the setting instead of changing their duplicate-error assertions.

  4. Preserve the owning connection's current LOAD policy through frontend background sessions for CALL and nested CALL. System-variable reads bypass identically named procedure locals, preserving the session/global namespace and existing ordinary local/user-variable lookup.

Use the same connection for SET and LOAD:

SELECT @@session.mo_pk_check_by_cn; -- 0 on a new connection
SET SESSION mo_pk_check_by_cn = ON; -- enable CN primary-key validation for LOAD
SET SESSION mo_pk_check_by_cn = OFF; -- bypass that validation

OFF can admit duplicate input primary keys; it does not remove duplicate rows. The independent TN switch can still reject conflicts, but historical testing showed TN ON alone did not detect duplicates within one input file. The new switch is session-only, does not apply to INSERT, and is not an all-unique-index checking switch. See the versioned design.

Validation:

  • Procedure-policy follow-up ce6352a010: both new regressions fail before their respective fixes. Final full frontend package passes (15.357 s); focused background/namespace tests pass (1.142 s); the complete authenticated two-CN LOAD fixture passes (6.870 s). It covers ON/OFF/ON, direct/CALL/nested CALL input and target conflicts, 1062/rollback/recovery, and nil/0/1 same-name procedure locals. Tests use -count=1 -vet=all; incremental four-package lint reports 0 issues. Independent gpt-6-astra medium final review passes.
  • Full owning packages pass on PR base 63a964a82f: planner 17.387 s, frontend 14.024 s, compiler 10.249 s. Focused cases cover OFF/ON typed plan shape, both planners, resolver errors/defaults, session cache invalidation, and internal compiler delegation. Scoped vet, incremental lint, formatting and diff checks pass.
  • Authenticated two-CN TestLoadRejectsDuplicatePrimaryKeys passes (6.219 s), covering session isolation, OFF/ON/OFF on identical LOAD text, invalid/global SET, prepared INSERT across SETs, and existing duplicate/rollback, composite-key, index, FK, parallel-file and cross-batch cases. PREPARE LOAD is not admitted by the existing parser; this change does not extend it.
  • Active ddl/alter.sql passes normal mo-tester comparison twice: 314 successful statements, 42 existing skips, zero failures each; teardown verified. Five other adjusted duplicate-LOAD BVT blocks retain their existing [Enhancement]: Hash join/Hash agg spill #3433 skips and were not executed. Their original error oracles remain intact.
  • Sampling regression checks sampled width/cardinality, header handling and denied file access; it fails without the context fix. Prior unchanged fileservice admission/provider/cancellation checks remain valid. Against the original three COS schemas/objects, the sampling correction restores MULTICN plans and baseline sampled statistics; this is plan evidence, not completed 100M throughput measurement.
  • Controlled Linux diagnostic build 2196656528 plus the same sampling and switch production patches, 16 CPU / 64 GiB, one identical 2M-row 857,722,330-byte file: PK-only OFF 5.19 s, ON 9.73 s, prior-good b24d1b3115 5.16 s. Both return 2M rows/distinct keys and key sum 2,000,001,000,000. OFF has six data writers and no hash-build/dedup operators; ON has one data writer and 16 hash-build/dedup operators. These are single bounded runs with different validation semantics, not statistical or original TKE throughput claims. ON input and existing-table conflicts return 1062 with rollback for both parallel options.

Original three-CN TKE 100M throughput for the new head remains pending in run 39540728649, dispatched for exact commit 579e0a1fad124ac4cafd77a88b018919d80dd21f. The earlier workflow run targets sampling-only commit c38e3715539749aee13f3175d4900593b53f6bb8 and cannot validate this switch. Design and integrated final review use gpt-6-astra with medium reasoning.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@iamlinjunhong iamlinjunhong changed the title fix(plan): preserve file access context for LOAD statistics fix(load): restore sampling context and make CN PK checks opt-in Oct 21, 2026
@matrix-meow matrix-meow added size/M Denotes a PR that changes [100,499] lines and removed size/S Denotes a PR that changes [10,99] lines labels Oct 21, 2026
@XuPeng-SH

XuPeng-SH commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 579e0a1fad124ac4cafd77a88b018919d80dd21f

Review completed. Read the assessment.

@XuPeng-SH

XuPeng-SH commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · done

Commit: 579e0a1fad124ac4cafd77a88b018919d80dd21f

Review completed. Read the assessment.

@mergify mergify Bot removed the dequeued label Oct 21, 2026
@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Oct 21, 2026
@XuPeng-SH

XuPeng-SH commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · done

Commit: ce6352a010492ebbc8134e014652d40bc2eacfe0

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-xupeng · review

Commit: ce6352a010492ebbc8134e014652d40bc2eacfe0

Assessment: approve

Reviewed the complete 30-file delta, design, callers, tests and frozen comments. Sampling preserves authorization and bounded cleanup; both LOAD planners share the session policy and existing cache lifecycle. The prior CALL/nested-CALL bypass is fixed and verified. Default-OFF duplicate-key behavior is an explicit documented tradeoff. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a14d34-4e51-79a3-a62d-6c9c16279dc8 · slot 0 · generation 0

Validation:

  • Verified exact HEAD/base, unchanged source, frozen-patch identity and git diff --check; receipt checks/1792570601288682424-4.json.

  • Isolation preflight passed. Native provenance verification passed after matching 190 native/build inputs; receipts checks/1792570210359360206-3.json and checks/1792570251987024833-36.json.

  • Full frontend, planner and compiler packages passed with -count=1 -vet=all and the supplied test-exec; owner-tests.log and receipt checks/1792570750847546399-4.json.

  • Authenticated two-CN TestLoadRejectsDuplicatePrimaryKeys passed, covering session isolation, policy transitions, direct/CALL/nested CALL, colliding procedure locals, duplicate errors, rollback, recovery and neighboring constraints; load-sql.log and receipt checks/1792570872035758036-4.json.

  • Command, source, exit and log reconciliation passed. Evidence is retained in validation-index.json, evidence-audit.log and review-notes.md under /home/xupeng/.local/state/mo-bot/jobs/34f1390e54648820db7e5756/attempt-1.

Limitations:

  • Did not independently run mo-tester or the original TKE/COS 100M-row workload. Five adjusted distributed BVT blocks retain preexisting skips; one unrelated owning-package test also skipped.

  • Coordinator local_validation was empty. Raw author/CI logs and the linked issue body were unavailable; external performance claims were not treated as independently verified results.

@mergify

mergify Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-21 23:52 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-22 00:48 UTC · at 460b96365a381e74916b044a99fc9423c33ad3fd · squash

This pull request spent 56 minutes 32 seconds in the queue, including 54 minutes 36 seconds running CI.

Required conditions to merge

@iamlinjunhong

Copy link
Copy Markdown
Contributor Author

补充 2026-10-23 在 129 上完成的 fresh 1T LOAD + 双 CN Q5/Q3 验收:包含 #30697 的版本使用默认 mo_pk_check_by_cn=OFF 重新导入后,Q5/Q3 已恢复到旧快基线水平。

对应 issue #30821 的同组验证记录:129 fresh 1T 默认OFF验收。

  • 新版:a949c88af0ed2cc4fe98e2ac32f0732a1235bd85,包含 fix(load): restore sampling context and make CN PK checks opt-in #30697 合并点 460b96365a381e74916b044a99fc9423c33ad3fd;旧快基线:e44d8f9bef62615237ec3618c04457e49bac6e7c。均使用官方镜像并记录实际 image ID/RepoDigest;a949 是本次验证版本。
  • 复用原始 TPCH SF1000 八文件(共 1,169,324,773,109 字节),两版分别 fresh LOAD,未跨版本复用数据库对象。新版实际导入连接确认默认 CN=0、DN=0,未执行 SET;旧版尚无 CN 开关,DN 默认0。新版 lineitem/orders LOAD 计划无 DEDUP。
  • 同一台129、两台实际参与执行的 AP CN,每台14逻辑CPU/55GiB、16GB fileservice memory cache、GOGC=200、GOMEMLIMIT=25000MiB;TN14CPU/32GiB、Log4CPU/8GiB。两组实际 cpuset/NUMA、资源和归一化配置相同,使用各自独立 DISK-V2 存储前缀。
  • 固定原始工具:mo-tpch@77081d5b3f24fec6e57b660427f0470ff73639ab、mo-load-data@f0fc5772667efd7908b756b728ed4a598a7fb0e8。SQL/DDL/golden/比较器未变;两份 runner 均禁用同一条全机 drop_caches 命令以保护其他服务。

每版每条查询一次预热、两轮正式,串行执行。以下来自原工具 cost.txt 的 SQL 客户端耗时,未计入结果比较或单独 EXPLAIN ANALYZE 的耗时,未挑选较快轮次。

查询 旧版正式1 / 2(秒) 新版默认OFF正式1 / 2(秒) 旧版均值(秒) 新版均值(秒) 新版耗时变化
Q5 34.944 / 35.127 33.164 / 33.131 35.0355 33.1475 −5.39%
Q3 37.332 / 37.086 33.934 / 34.053 37.2090 33.9935 −8.64%

预热另行保留:旧版 Q5/Q3 为38.855/37.869秒,新版为37.015/34.519秒。八表行数均符合预期(lineitem 5,999,989,709、orders 1,500,000,000),两版合计12次查询的原始 golden 校验全部通过。lineitem LOAD 耗时旧版2137.074秒、新版2140.176秒,约+0.15%。

性能恢复同时有布局和传输量证据:

证据 旧版 新版默认OFF
Q5 两轮平均 AP MORPC 输出 2.122073 GiB 2.114919 GiB
Q3 两轮平均 AP MORPC 输出 0.144383 GiB 0.116580 GiB
lineitem 对象数 10,178 10,178
orders 对象数 1,908 1,908
lineitem 对象范围宽度总和 / orderkey键域 1.107545173 1.107545173
orders 对象范围宽度总和 / orderkey键域 1.926939824 1.926939824

两代对象 ID 无交集,但每个对象的行数、metadata_scan返回的大小、orderkey min/max组成的多重集合完全一致;各组查询前后对象清单均未变化。lineitem这里比较的是复合主键第一分量 l_orderkey 的范围。正式查询期间两台CN均有显著RPC输出,另采集的诊断执行计划包含两个实际CN地址。

RPC为查询窗口内进程级 MORPC output 增量,两台AP求和一次,计数单调,未叠加input,不是精确SQL归因或物理NIC字节。相邻查询短间隙的最大合计输出为新版45,944字节、旧版25,625字节,远小于正式窗口。保留采样未观察到spill reserve/reject;诊断plan的SpillSize为0,各节点无OOM、RestartCount=0。测试正常退出,任务实例/临时数据/租约已清理,原始输入及结果证据保留。

结论范围:默认OFF、重新导入后的Q5/Q3,在上述129同机双CN环境已恢复;无需追加默认路径补丁。 已有旧数据对象不会因升级自动重新布局。此结果不替代TKE物理网络/存储环境、完整TPCH套件或CN检查ON路径验收,也不构成同SHA ON/OFF的严格因果实验;OFF保留其既定校验策略差异。

证据与测量边界

固定顺序为新版、旧版,每版两轮正式;结果属于工程验收,不宣称统计等价。正式计时为原客户端时间,未导出正式statement Exec.Run;远端operator统计未完整导出。新版Q3单独analyzed plan采于同镜像重启后,仅作诊断,不混入正式成绩。新版首次server stdout在补采诊断时被覆盖;原始正式工具日志、结果、计时、探针、Q5plan、对象清单及首次运行Docker检查均保留。

129证据:/root/issue-30821-20261023 和 /data3/mo-benchmark-runs/private-issue30821-20261023-r4/slot-a。新旧压缩包均在收回本地后校验SHA256一致:

  • new-evidence.tar.gz: ac7e04f387ba145c4bffe3988a21ce09a0e12a655b8008e0c6eeb9393f7c6043
  • good-evidence.tar.gz: e02c5a2a9c168942400d66d0883cd1048412364727922b15de47407f903705e4

This branch was previously deployed

1 inactive deployment
ci — 73c16765 Deployed Oct 22, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/api-change kind/bug Something isn't working kind/enhancement size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants