Skip to content

fix: reject invalid global time_zone, save DATA BRANCH DIFF temporal results, reject snapshot-qualified write targets - #32456

Merged
mergify[bot] merged 11 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/combined-priority-1109
Nov 14, 2026
Merged

mergify[bot] merged 11 commits into
matrixorigin:mainfrom
MatrixAdventurer:fix/combined-priority-1109

Conversation

@MatrixAdventurer

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:

Fixes #31714
Fixes #31547
Fixes #31550
Fixes #31688

What this PR does / why we need it:

把此前被关闭、未合入的三个修复中影响最大的几项(锁死登录、进程崩溃、静默写错表)合成一个 PR,基于当前 main(11d2e1ef)重新整理。三项修复的代码互不重叠:

  1. [Bug]: bad global time_zone locks out all new connections persistently #31714:SET GLOBAL time_zone 写入非法时区后,所有新连接都无法登录(原 fix(frontend): validate SET GLOBAL time_zone before persisting it #31830)
    • 现状:SET GLOBAL time_zone = 'Mars/Phobos' 返回 OK 并持久化,之后每个新连接都报 1815 unknown time zone,重启也不能恢复。
    • 修复:把 updateTimeZone 的校验抽成 resolveTimeZone,SetGlobalSysVar 在持久化 time_zone 之前先用它校验。非法值直接报错,和 SET SESSION 的行为一致。
    • 文件:pkg/frontend/variables.go、pkg/frontend/types.go
  2. [Bug]: saving DATA BRANCH DIFF with DATETIME crashes the service #31547 / [Bug]: saved DATA BRANCH DIFF corrupts TIMESTAMP precision and timezone #31550:save_query_result = on 时,DATA BRANCH DIFF 遇到 DATETIME/TIME 列会让服务进程崩溃;TIMESTAMP 丢精度、时区不对(原 fix(frontend): parse temporal text when saving DATA BRANCH DIFF results #31842)
    • 现状:DIFF 结果中的时间值是文本,保存结果时 convertRowsIntoBatch 对 types.Datetime/Time/Date 做类型断言,直接 panic,整个 CN 退出。
    • 修复:DATE/TIME/DATETIME 同时接受原生值和文本(按列声明的 scale 解析);结果列保留 TIME/DATETIME/TIMESTAMP 的小数秒精度;TIMESTAMP 文本按会话时区解析,不再用进程时区。
    • 文件:pkg/frontend/util.go、pkg/frontend/query_result.go
  3. [Bug]: snapshot-qualified DML/DDL silently targets the live table #31688:对 t{snapshot='sp'} 执行 DML/DDL 会静默改动当前表(原 fix(plan): reject DML/DDL that targets a snapshot-qualified table #31854)
    • 现状:INSERT/UPDATE/DELETE/ALTER/TRUNCATE/DROP ... t{snapshot='sp'} 都返回成功,实际写进了当前表,快照不变,也没有任何提示。
    • 修复:BuildPlan 入口新增 rejectSnapshotQualifiedWriteTarget。写入目标带快照/时间戳限定时,统一报 not supported: <OP> on a snapshot-qualified table。覆盖的语句有 INSERT、REPLACE、UPDATE(含多表)、DELETE(含多表)、ALTER、TRUNCATE、DROP TABLE、LOAD、INSERT ALL、CREATE/DROP INDEX、RENAME。带快照限定的表作为只读来源(INSERT ... SELECT、UPDATE/DELETE 的 JOIN 来源)不受影响。
    • 文件:pkg/sql/plan/build.go、pkg/sql/plan/snapshot_write_target.go

How this PR does it or why it needs it:

  • 在新分支上 cherry-pick 原 PR 的提交(a8dfd88d、4556f673、375cf9b9、768ace77),过程中没有冲突。
  • 适配当前 main:CompilerContext.Resolve 现在多了一个 *TableResolution 参数,相应补上 nil。
  • 为了把规模控制在 10 个文件以内,把两个 frontend 单测合并成 pkg/frontend/time_zone_and_saved_temporal_test.go,三组 BVT 合并成 test/distributed/cases/util/priority_fixes_31547_31688_31714.{sql,result}。用例内容不变,按 issue 分段注释。
  • 规模:10 个文件,+790/-40。其中代码改动 6 个文件,其余 4 个是测试。

Evidence(本地,main 11d2e1ef 对比本分支)

  • 端到端(单机 launch,unshare -rn 隔离网络):
  • BVT util/priority_fixes_31547_31688_31714.sql:本分支 57/57 通过;main 13/57(DIFF 让进程崩溃后,后续 40 条全部 ABNORMAL)。
  • 相关 BVT 目录(本分支):system_variable 636/636,git4data/branch/diff 1976/1976,结果与 main 相同。snapshot 18389/18454:65 条失败全部在 snapshot_restore_account_level.sql,原因是本机资源准入报 execution resource admission rejected ... cap=0,与本改动无关,main 在同一目录也出现同类资源错误。全目录没有任何语句命中新的 snapshot-qualified 报错。
  • 单测:go test ./pkg/frontend/ ./pkg/sql/plan/ 全部通过(含新增的 TestSetGlobalTimeZoneRejectsUnknownZone、TestConvertRowsIntoBatchTemporalText 和 snapshot write-target 用例)。
  • 静态检查:go vet、molint check、golangci-lint v2.14.0 -c .golangci.yml --new-from-rev=origin/main(./pkg/frontend/...、./pkg/sql/plan/)均无问题。

Special notes for your reviewer:

本操作由 LW 授权的 Grok Bot 智能体执行。

SET GLOBAL time_zone stored any string, and every new session then failed
to initialize with "unknown time zone", even after a restart. Extract the
parsing of updateTimeZone into resolveTimeZone and call it from
SetGlobalSysVar, so an unknown zone is rejected like SET SESSION does.

Fixes matrixorigin#31714

(cherry picked from commit a8dfd88)
DATA BRANCH DIFF renders its rows as text. With save_query_result=on,
convertRowsIntoBatch asserted DATE/TIME/DATETIME cells to MatrixOne values
and panicked on the text (service crash), dropped the declared
fractional-second scale of TIME/DATETIME/TIMESTAMP columns, and parsed
TIMESTAMP text in the process zone instead of the session zone.

Parse DATE/TIME/DATETIME text, keep the column scale from the result column
definition, and read TIMESTAMP text in the session time zone.

Fixes matrixorigin#31547
Fixes matrixorigin#31550

(cherry picked from commit 4556f67)
A {snapshot=...}/{timestamp=...} qualifier on an INSERT/REPLACE/UPDATE/DELETE
target or an ALTER/TRUNCATE/DROP TABLE name was ignored and the statement
modified the live table. Reject such targets at plan time; snapshot-qualified
tables stay valid as read sources.

Fixes matrixorigin#31688

(cherry picked from commit 375cf9b)
- an unqualified SET column of a multi-table UPDATE now counts as a write
  to the snapshot-qualified table that has that column;
- LOAD DATA, INSERT ALL, CREATE INDEX, DROP INDEX and RENAME TABLE on a
  snapshot-qualified table are rejected as well;
- alias matching is case-sensitive under lower_case_table_names=0.
Adds unit coverage for each case with controls.

(cherry picked from commit 768ace7)
- snapshot write-target guard: pass the TableResolution argument that
  CompilerContext.Resolve now takes.
- merge the matrixorigin#31714 and matrixorigin#31547/matrixorigin#31550 frontend unit tests into one file and
  the three BVT cases into util/priority_fixes_31547_31688_31714 to keep
  the combined PR within 10 files.
@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 →

@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

… baseline

The existing float-switch exemption moved with the function body to
convertRowsIntoBatchInLocation; no switch is added.
… baseline entry

Result columns come from mysqlColDef2PlanResultColDef, which only yields
T_float32/T_float64, so the partial float switch is intended. Restore the
baseline entry rather than renaming it.
@XuPeng-SH

XuPeng-SH commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 86d6fbf32cfb96ed8e0155d6124cec3e568ae4cb

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-local · review

Commit: 86d6fbf32cfb96ed8e0155d6124cec3e568ae4cb

Assessment: approve

The three fixes close the reported write-target and temporal-result failures and reject invalid global timezones before persistence. Shared timezone and temporal parsers remain authoritative; the targeted planning guard preserves historical read sources without adding persistent state. No actionable correctness or design findings remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Read the complete ten-file delta, all discussion entries and all four linked issues, including the TIME follow-up. Traced global persistence/session initialization, temporal rendering/saved-result readback, and DML/DDL target binding through PREPARE and EXPLAIN.

  • Reused frozen-head evidence.json CI successes for shared build, Ubuntu/x86 UT, arm64 SCA, UT coverage, and PROXY/PESSIMISTIC BVT. Reviewed the new UT and SQL oracles for precision, session timezone, NULLs, unchanged globals/live tables and permitted historical read sources.

  • Local git diff --check passed for 71390fb..86d6fbf; receipt checks/1794641118143085628-2.json, retained output diff-check.log and validation-record.json.

Limitations:

  • No fresh local Go or cluster execution. Captured CI conclusions are reused; raw CI/author logs are unavailable, and author-reported baseline experiments and statement counts were not independently replayed.

  • The timezone change prevents new invalid global settings; it does not repair already-invalid persisted values or change the existing unknown-zone error code.

@mergify mergify Bot added the queued label Nov 14, 2026
@mergify
mergify Bot merged commit 625865c into matrixorigin:main Nov 14, 2026
@mergify

mergify Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

✅ Merged into main as 625865c at 07:27 UTC

Less than a minute in the queue, with no time running CI.

So far

  • ✅ Entered the queue Sat 14 Nov, 07:27 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged 07:27 · 625865c · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

1 inactive deployment
ci — 86d6fbf3 Deployed Nov 14, 2026 by MatrixAdventurer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

3 participants