Repository navigation
fix: support prepared TIME numeric arithmetic - #29036
Conversation
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Force review for exact head 72f9c2d.
Scope reviewed: all 3 changed files and the prepared TIME arithmetic binding/execution paths.
- TIME is handled only as a numeric-context hint for prepared-marker inference; the TIME expression itself remains TIME. The hint preserves the operand scale and uses the existing decimal coercion route.
- At execute time, numeric protocol/source values are rebound through their runtime type instead of being narrowed to the provisional TIME-derived decimal hint. Explicit CAST expressions remain outside this implicit-cast branch.
- Coverage includes both operand orders for +, -, *, /, %, and DIV; nested parameters; scale 0 and scale 6; explicit string casts; integer and decimal transport; SQL/binary source types; large integer values; and actual expression execution.
- The implementation keeps non-TIME/date boundaries explicit and does not broaden ordinary unsupported-type behavior.
The PR is mergeable without conflict and only behind the base branch. GitHub checks were unstable during this review, so I am not asserting a green-CI result here.
No evidence-backed P0/P1/P2 blocker found. This is a comment-only review because the PR is authored by the review requester.
XuPeng-SH
left a comment
There was a problem hiding this comment.
GPT-6 Astra medium independent review for exact head 72f9c2d.
P2 — missing real prepared SQL/protocol regression coverage.
The new execution tests manually construct SourceType and RuntimeType and call planner specialization directly. They do not verify the frontend's real PREPARE/EXECUTE path, reuse of the same prepared statement with changed parameter types, or the binary-protocol branch as it is actually produced by the protocol layer. The PR also does not add a real BVT for these paths.
Please add a real PREPARE/EXECUTE regression, including decimal and NULL values, repeated execution with changed parameter types, result precision/scale assertions, and a binary-protocol entry-point case where applicable. The direct planner tests are useful unit coverage but do not close this end-to-end contract.
Astra medium found no P0/P1 or other P2 issue and no clear flaky path. This is comment-only because the PR is authored by the review requester; code review should not be treated as approve until this validation gap is closed.
aptend
left a comment
There was a problem hiding this comment.
Reviewed exact head 72f9c2df8a9be5e29ae42f9671aeb0f933c33956 and found a blocking execute-time coercion regression. The focused tests added by this PR pass, but a counterexample covering the other advertised operators fails as described inline. Please preserve the direct TIME coercion contract and add public PREPARE/EXECUTE plus binary-protocol regression coverage before re-review.
| return nil, typedErr | ||
| } | ||
| if typedOK { | ||
| boundArgs[i] = typed |
There was a problem hiding this comment.
[P1] Preserve the TIME operand when rebinding the parameter
At PREPARE time the TIME operand has already been wrapped in its implicit DECIMAL64(18, scale) cast. This branch replaces only the parameter-side cast and then rebinds the outer operator, so boundArgs now looks like DECIMAL64 + INT64 instead of TIME + INT64. The common-decimal resolver therefore promotes +, -, and % to DECIMAL128(38, scale), while the direct temporal coercion rule keeps those same operations in DECIMAL64(18, scale).
I reproduced this on the exact head through both SQL-style SourceType=int64 and binary-style RuntimeType=int64: select cast('03:04:05.123456' as time(6)) + ? specializes to DECIMAL128, whereas select cast('03:04:05.123456' as time(6)) + cast(10 as signed) is DECIMAL64. The difference is not metadata-only: with 9223372036854775807, the prepared form returns 9223372036854775808.000000, but the ordinary form raises the DECIMAL64 overflow required by the existing TIME/INT64 contract. - and % show the same domain drift.
Please rebind from the original TIME expression, or otherwise preserve its temporal coercion provenance, and add real SQL PREPARE/EXECUTE and binary-protocol regressions for all supported operators, including this INT64 boundary case.
72f9c2d to
667444b
Compare
|
修复并推送 commit 上一轮 CI 本次修复:
本地通过 新 CI 已启动:
|
|
CI repair pushed in 6bd38d9. Root cause: PREPARE-time numericAstTypeScan treated the synthetic DECIMAL64 context from TIME as a genuine numeric operand. For CAST(NULL AS SIGNED) + ?, that widened the nested domain to DECIMAL256; the outer resolver then rejected [TIME, DECIMAL256] before execute-time NULL-envelope rebinding could run. Fix: track TIME-derived decimal as a temporal hint, exclude it from otherwise integral subtrees, and keep weak-decimal literals deferred so explicit outer DECIMAL context is preserved. No resolver-table or test-only bypass. Coverage: retained the original regression; added reverse operand order, non-NULL signed result-4 control, explicit DECIMAL plus weak-literal context and DOUBLE control; extended the existing prepare BVT fixture with metadata checks. Validation: focused prepared-time tests, weak-literal counterexample, and the complete pkg/sql/plan test binary pass locally; go test -c, go vet ./pkg/sql/plan, gofmt, and git diff --check pass. Fresh remote CI/BVT are now running and remain pending. |
|
Rebased onto latest main and pushed Adopted the bounded optimization reviewed in this update: compute the temporal peer once per TIME |
|
Updated and rebased onto latest Fixes included:
Validation at exact pushed head
Remote CI is intentionally not awaited or claimed. |
|
Final verification on head
Remote CI was not awaited. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Astra medium review on current head bfa4f4a.\n\n发现 1 个 P2,未发现 P0/P1:\n\n[P2] ABS 的 fallback 重绑会撤销 TIME 整数边界转换,改变结果类型及溢出行为。位置:pkg/sql/plan/visit_plan_rule.go:1369、1509。\n\n反例:\nPREPARE p FROM 'SELECT ABS(CAST(''00:00:01'' AS TIME(0)) + ?)';\nSET @v = CAST(9223372036854775807 AS SIGNED);\nEXECUTE p USING @v;\n\n主路径会先把完成的整数操作数转换到 TIME 的 DECIMAL64 边界;ABS 后的 rebindPreparedNumericExprWithBound 从原始表达式重建参数,剥离隐式 cast,直接调用 BindFuncExprImplByPlanExpr,没有再次应用 coercePreparedTemporalIntegerOperand。于是 TIME peer 可能按 DECIMAL64 + INT64 -> DECIMAL128 选型,绕过本应发生的 DECIMAL64 溢出并改变小整数结果 precision。当前新增保护只覆盖 NULL envelope,非 NULL 路径仍受影响。\n\n建议让 ABS 等 fallback 重绑同样遵守 TIME 边界转换,并补充非 NULL、溢出、NULL 后恢复三种执行状态测试。现有 integer-argument 整合回归已有闭合证据;当前 head UT/BVT 已通过。本 PR 为自有 PR,提交 COMMENT。
XuPeng-SH
left a comment
There was a problem hiding this comment.
Force re-review of exact head 7f27de3.
未确认 P0/P1/P2 代码缺陷。此前 ABS fallback 丢失 TIME 整数边界的问题已修复:递归 numeric fallback 在 overload resolution 前重新对已完成的整数 operand 应用 TIME 边界转换,保留嵌套整数运算、溢出语义、TIME(0/6) scale、显式 CAST 和乘法宽域;SIGN 与完整参数列表的 ELT rebinding 也已检查。
已复查完整 diff、planner/frontend 执行路径、NULL envelope、参数解码、runtime-plan cache 和新增测试,未发现新的 cache contamination、清理、liveness 或无界保留问题。
验证边界:本次为只读 evidence review,未独立重跑测试;检查了已有 focused planner、frontend、embed PASS 日志。未等待 CI 或重跑外部 BVT/multi-CN。嵌套 mixed signed/unsigned 的负值/underflow 组合及真实协议下 SIGN/ELT 覆盖仍较弱,但目前没有可确认的代码反例。PR 已声明的 ABS(TIME + (? + 1)) PREPARE 限制不宣称已修复。
本 PR 为自有 PR,提交 COMMENT。
XuPeng-SH
left a comment
There was a problem hiding this comment.
Force re-review of exact head 8d1b277.
未确认 P0/P1/P2;prepared TIME arithmetic 当前未发现阻断回归。
7f27de3 -> 8d1b277 是 rebase,range-diff 显示 15 个 PR commits 均 patch-equivalent。我重新核对了当前 planner/frontend/embed 路径及新 base binder 交互。
TIME integer boundary 在普通 specialization 和 ABS/SIGN/ELT fallback rebinding 中仍存在;nested integer arithmetic 先完成再做 TIME boundary cast,TIME(0/6) scale、乘法宽域、显式 CAST 边界、NULL envelope、runtime plan cache/reuse 和 binary execute 错误清理均保持。
当前 head 的 Linux UT、真实 MySQL-protocol TIME suite、SCA 和 CI Required 已通过;PROXY BVT 中 prepared_time_arithmetic.sql 为 62/62 成功,0 ignored/abnormal。
验证缺口:nested unsigned underflow、mixed signed/unsigned extremes、真实 TCP SIGN/ELT error recovery 覆盖仍不完整;这些不是已确认 defect。ABS(TIME + (? + 1)) 的 PREPARE 拒绝仍明确不在本修复范围。
另外,PR 正文仍引用旧 head 7f27de3 并写 fresh Linux CI pending,建议更新为当前 head/CI 状态。本 PR 为自有 PR,提交 COMMENT。
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #28963
What this PR does / why we need it:
Specialize prepared TIME arithmetic from execution-time source types without losing fractional precision, changing ordinary-query overflow behavior, or leaking one execution's types into the next.
3ac87c30625fc082391e5384a4c94e50a2916cf6.Validation
Current head:
7f27de35bd1cbc35455d2908a036763796313c24. macOS arm64, Go 1.26.4, own-worktree native libraries.pkg/sql/plan: PASS (6.132s).plan,frontend,embed): PASS, 0 lint issues including unused checks. Molint exits 0; its seven historical diagnostics were reproduced on the frozen main baseline and matched.The existing BVT SQL/result pair was reviewed but not rerun in an external multi-CN deployment. Fresh Linux CI is pending, not claimed green. Nested
ABS(TIME + (? + 1))PREPARE rejection exists before and after this execute-time repair and is not claimed fixed. No measured performance-parity claim is made; this is bind-time specialization, not a new per-row algorithm.