Repository navigation
fix(frontend): parse temporal text when saving DATA BRANCH DIFF results - #31842
MatrixAdventurer wants to merge 2 commits into
Conversation
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
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 559a52b1f42eced8e95f6af0cfba41793748e73e
Assessment: request_changes
The common crash and precision cases are addressed, but saving timestamps during a repeated daylight-saving hour can still corrupt the stored instant.
Model: gpt-6-astra / xhigh
Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2
- P2
pkg/frontend/util.go:1862: Save a DATA BRANCH DIFF containing TIMESTAMP(0) value 2024-11-03 06:30:00 UTC with session time_zone='America/New_York'. DIFF renders it as the ambiguous local time 01:30:00.
Impact: Parsing that text reconstructs 05:30 UTC, shifting the saved value by one hour; RESULT_SCAN and downstream INSERT SELECT retain the corruption. Preserve the original typed timestamp or equivalent instant information through saving, and test both occurrences of the repeated hour.
Evidence: output.go:159-162 discards the offset before query_result.go:459 supplies the session zone. ParseTimestamp reaches datetime.go:590's time.Date conversion. The retained primitive-level probe confirms 06:30Z becomes 05:30Z. With a fixed-EST process, the baseline preserves this TIMESTAMP(0), establishing a newly affected configuration. See temporal-fold.md and timestamp-fold-probe.log.
Validation:
-
Reviewed all five changed files, affected producers/consumers, both linked issues and both discussion entries.
-
Timestamp-fold probe and unaffected controls completed successfully; receipt 1793348893659884216-3.json.
-
Frozen-head CI reports successful build, UT, SCA, coverage and multi-CN BVT.
-
Final source, patch, discussion and receipt audit passed; receipt 1793349095923661704-4.json.
Limitations:
-
The counterexample combines source tracing with a Go timezone primitive probe; the retained SQL reproduction was not executed against MatrixOne.
-
Full local frontend and live-server suites were not rerun.
|
相关 issue 将根据优先级计划修复。 |
…results, reject snapshot-qualified write targets (#32456) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [x] 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. **#31714:`SET GLOBAL time_zone` 写入非法时区后,所有新连接都无法登录**(原 #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. **#31547 / #31550:`save_query_result = on` 时,`DATA BRANCH DIFF` 遇到 DATETIME/TIME 列会让服务进程崩溃;TIMESTAMP 丢精度、时区不对**(原 #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. **#31688:对 `t{snapshot='sp'}` 执行 DML/DDL 会静默改动当前表**(原 #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` 隔离网络): - #31547:main 上执行 `DATA BRANCH DIFF c AGAINST b` 后客户端报 2013,服务进程退出;本分支正常返回 `c, UPDATE, 1, 2024-01-02 00:00:00.654321, 04:05:06.654321, ...`,服务存活。 - #31688:main 上 `INSERT INTO snap_t{snapshot='sp'} ...` 成功,当前表多出一行;本分支报 `20105 not supported: INSERT on a snapshot-qualified table 'snap_t'`,当前表不变。 - #31714:main 上 `SET GLOBAL time_zone='Mars/Phobos'` 成功,之后新连接报 `1815 unknown time zone Mars/Phobos`;本分支 SET 时直接报错,全局值仍是 `SYSTEM`,新连接正常。 - **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: - 这三项修复之前分别在 #31830、#31842、#31854 提交,2026-10-30 被关闭(“相关 issue 将根据优先级计划修复”)。这次按严重程度挑出:会锁死登录、会让进程崩溃、会静默写错表的三项,三个 issue 目前都还开着,也没有其他修复 PR。 - 非法时区的错误码沿用 SET SESSION 现有的行为(`unknown time zone ...`),没有改成 MySQL 的 1298,以免改变会话级的既有行为。 > 本操作由 LW 授权的 Grok Bot 智能体执行。 Approved-by: XuPeng-SH <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #31547
Fixes #31550
What this PR does / why we need it:
With
save_query_result = on, saving aDATA BRANCH DIFFresult:DATETIME(orDATE/TIME) column ([Bug]: saving DATA BRANCH DIFF with DATETIME crashes the service #31547);TIMESTAMP(n)/DATETIME(n)/TIME(n)columns and shiftedTIMESTAMPvalues by the process time zone instead of the session time zone ([Bug]: saved DATA BRANCH DIFF corrupts TIMESTAMP precision and timezone #31550).RESULT_SCANandINSERT ... SELECT FROM result_scan(...)then returned/persisted the wrong values.Cause:
DATA BRANCH DIFFrenders its rows as text, butconvertRowsIntoBatchassertedDATE/TIME/DATETIMEcells to MatrixOne values (row.(types.Datetime)→ panic on a string).mysqlColDef2PlanResultColDefbuiltTIME/DATETIME/TIMESTAMPresult types with scale 0, ignoring the column's declared decimals, andTIMESTAMPtext was parsed withtime.Local.Fix (
util.go+79/-13,query_result.go1 line):DATE/TIME/DATETIMEcells accept either the MatrixOne value or its text form; anything else is an error instead of a panic.TIME/DATETIME/TIMESTAMPresult columns keep the scale the column definition declares (0–6).trySaveQueryResultpasses the session time zone, used to readTIMESTAMPtext (convertRowsIntoBatchInLocation;convertRowsIntoBatchkeeps its old signature/behaviour for other callers).Tests
pkg/frontend/save_result_temporal_text_test.go: text DATE/TIME(6)/DATETIME(6)/TIMESTAMP(6)/TIMESTAMP(3) cells with a session zone different from the process zone keep value, scale and zone; NULLs stay NULL; a non-temporal cell returns an error. GREEN here (on main the text cells panic on the type assertion).go test ./pkg/frontendpasses.git4data/branch/diff/diff_save_result_temporal.sql(the issues' scenarios: DIFF with changed TIMESTAMP(6)/TIMESTAMP(3)/DATETIME(6)/TIME(6)/DATE,RESULT_SCAN,INSERT ... SELECTand a<=>comparison with the source branch): main 10/20 then the server crashes (10 abnormal), PR 20/20.git4data1 failed both (clone/clone_db_table_to_new_db_table, local env),save_query_result0/0,query_result9/9 (same files, local env).Merge Danger
Low. Only saved results whose temporal cells arrive as text change (previously a panic or wrong values). Saved
TIME/DATETIME/TIMESTAMPresult columns now carry their declared scale instead of 0, soRESULT_SCANof e.g.select now(6)keeps the microseconds.