Repository navigation
Description
- I have checked the existing issues. This is a remaining unary-operator path related to the closed temporal-coercion issue [Bug]: DATE/DATETIME/TIME use incorrect numeric coercion in bitwise and scalar functions #31904 / PR fix: correct temporal numeric coercion for bit consumers #32642, not a claim that the verified binary-operator cases regressed.
Branch Name
main
Commit ID
517e169 (includes e765c5f / PR #32642)
Other Environment Information
- Hardware: Apple Silicon, 10 cores
- OS: macOS, arm64
- Deployment: isolated 1 LOG / 1 TN / 1 CN production build, MySQL protocol
- Go: 1.27.1
Actual Behavior
Unary bitwise NOT (~) rejects native DATE, TIME, DATETIME, and TIMESTAMP operands:
SELECT ~CAST('2024-06-18' AS DATE);
-- ERROR 20203 (HY000): invalid argument operator unary_tilde, bad value [DATE]The same temporal values are accepted by the binary bitwise operators, shifts, and BIT_COUNT after #32642. An executable matrix over 10 rows and all four temporal types found zero value mismatches for supported operations, but 40 direct-versus-explicit-cast disposition differences for unary ~.
Expected Behavior
Unary ~ should use the same native temporal-to-integer coercion as the other bitwise consumers. For example, both existing paths below return the same numeric result, so the direct temporal operand should not be rejected:
SELECT
~(CAST('2024-06-18' AS DATE) & -1) AS via_bit_and,
~CAST(CAST('2024-06-18' AS DATE) AS SIGNED) AS via_cast;
-- via_bit_and = via_cast = 18446744073689310997Steps to Reproduce
-- Fails on the stated main revision:
SELECT ~CAST('2024-06-18' AS DATE);
SELECT ~CAST('01:02:03' AS TIME);
SELECT ~CAST('2024-06-18 01:02:03' AS DATETIME);
-- Existing equivalent paths succeed and agree:
SELECT
~(CAST('2024-06-18' AS DATE) & -1),
~CAST(CAST('2024-06-18' AS DATE) AS SIGNED);Additional information
Source trace:
pkg/sql/plan/function/list_operator.go:2418-2547: theUNARY_TILDEregistration has nointegerParametersdeclaration.- In contrast, the sibling
®istration atlist_operator.go:3444-3450declares both positions astemporalOnlyIntegerParameter; the other binary bitwise registrations do likewise. - Consequently
integerParameterForPosition("unary_tilde", 0)cannot driveappendSourceDependentIntegerArgumentintoTemporalIntegerArgumentCastOverload. pkg/sql/plan/function/type_check.go:1070-1081:unaryTildeTypeMatchonly adds an implicit integer cast for CHAR/VARCHAR/TEXT, then falls back to direct overload matching, which rejects the native temporal types.
This appears to be an uncovered unary path left by #31904 rather than a binary-bitwise regression. Explicit CAST(... AS SIGNED) is a workaround.
Activity
fix: accept native temporal operands in unary bitwise NOT (#32927)
XuPeng-SH commentedon Nov 20, 2026
QA 交接补充:#32927 已于 2026-11-20 08:20:53 UTC 合入 main,merge SHA
d0fee0362b16e491dfc979b8f208e5ce40439c31,最终 head9823940c5311464f6b1eeee8bca4e5f6aa9a844e。保留现有 QA 负责人 slyunnn 和 open 状态;交接不代表验收通过。修复为 UNARY_TILDE 的第 0 参数声明现有 temporalOnlyIntegerParameter 契约,使原生 DATE/TIME/DATETIME/TIMESTAMP 进入既有 temporal-to-integer 转换;非时间类型不走该转换,不新增转换机制。
作者报告:新 planner UT 在基线因四种时间类型被拒绝而失败,修复后通过,覆盖字面量、列、NULL、零值、负值/小数 TIME、UTC TIMESTAMP、原生时间参数的 prepared ~? 及模板复用,含整数/文本对照;temporal_numeric_consumer BVT 60/60,另五个相邻用例分别 210/210、30/30、47/47、118/118、25/25;plan/function 完整包测试、TestTypeSwitchFamilies、go vet 和增量 lint 通过。这些来自 PR 作者记录,本轮未执行本地测试或核验原始日志。
建议在包含该 merge SHA 的 main 上复验原 SQL 及直接 ~、位与后取反、显式 SIGNED cast 三条路径的结果一致性,补充四类时间列、NULL/边界、小数及负 TIME、TIMESTAMP 时区和 prepared 参数复用;保留整数、文本、binary/BIT 对照。作者未本地运行完整 BVT 和仓库全量 SCA;不据定向结果宣称全量验收通过。本次只确认 main 合入,不自动要求 4.2 backport。
slyunnn commentedon Nov 25, 2026
Regression and extended verification for #32873 (2026-11-25)
Verification Environment
main@ca5325ce683a60ef6d7f0888b68d709de2ea8389— test(optools): accept a KILL-escalated drain in the publication latch test (#33188). Fetched at verification start, freshly built, andgit_version()checked at each endpoint. Isolated2 CN / 1 TN / 1 Log service / Proxyon macOS arm64. Proxy6001, CN116001, and CN216002each executed the test SQL through PyMySQL text protocol and native temporal prepared parameters through MySQL Connector's binary protocol, in default andMATRIXONE_NATIVEmodes.Fix: #32927, fix: accept native temporal operands in unary bitwise NOT, merge
d0fee0362b16e491dfc979b8f208e5ce40439c31.What Was Covered
~,~(operand & -1)and explicitSIGNEDcast returned identical expected values.+00:00,+08:00, and-05:00, at all three endpoints.~?reused with DATE, DATETIME, TIME, fractional TIME, NULL and another DATE; all endpoints and both SQL modes.20203; connections stayed usable.temporal_numeric_consumerBVT passed64/64including JDBC metadata. MOTR record and replay each passed24/24statements.405/430with metadata checking, with25metadata expectation differences outside the unary-temporal cases. A separate result-only rerun passed430/430; this does not count those metadata checks as passing or establish their root cause. No expected results were changed.4.2-devwas not a target. Large data and engine-parallel verification are unnecessary for this scalar conversion defect. Tests ran serially; case scheduling is not an engine-parallel assertion.Findings
The reported native-temporal unary-NOT failures no longer reproduce. A negative
timedeltadiagnostic in MySQL Connector was excluded after inspecting its wire serializer: it encoded a different TIME than intended. Negative TIME remains directly covered by SQL columns; native binary TIME and fractional TIME were verified with correctly encoded inputs.MOTR / BVT Coverage
Added
issue_32873_temporal_unary_noton MOTRmain, sourcec179721d9fec022a536db3f95271d52d49f9720f, daily cherry-pickfd2406b3, in MOTR #389. Record and replay ran with-j 1and passed.Final Conclusion
The reported bug is verified fixed in the tested main build. Neighboring metadata differences remain explicitly outside the passing test claims.