Skip to content

[Bug]: unary bitwise NOT rejects native temporal operands after temporal coercion fix #32873

Done

Description

@XuPeng-SH

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 = 18446744073689310997

Steps 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: the UNARY_TILDE registration has no integerParameters declaration.
  • In contrast, the sibling & registration at list_operator.go:3444-3450 declares both positions as temporalOnlyIntegerParameter; the other binary bitwise registrations do likewise.
  • Consequently integerParameterForPosition("unary_tilde", 0) cannot drive appendSourceDependentIntegerArgument into TemporalIntegerArgumentCastOverload.
  • pkg/sql/plan/function/type_check.go:1070-1081: unaryTildeTypeMatch only 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

  1. added
    kind/bug
    on Nov 17, 2026
  2. assigned and unassigned on Nov 20, 2026
  3. XuPeng-SH commented on Nov 20, 2026

    @XuPeng-SH
    ContributorAuthor

    QA 交接补充:#32927 已于 2026-11-20 08:20:53 UTC 合入 main,merge SHA d0fee0362b16e491dfc979b8f208e5ce40439c31,最终 head 9823940c5311464f6b1eeee8bca4e5f6aa9a844e。保留现有 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。

  4. slyunnn commented on Nov 25, 2026

    @slyunnn

    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, and git_version() checked at each endpoint. Isolated 2 CN / 1 TN / 1 Log service / Proxy on macOS arm64. Proxy 6001, CN1 16001, and CN2 16002 each executed the test SQL through PyMySQL text protocol and native temporal prepared parameters through MySQL Connector's binary protocol, in default and MATRIXONE_NATIVE modes.

    Fix: #32927, fix: accept native temporal operands in unary bitwise NOT, merge d0fee0362b16e491dfc979b8f208e5ce40439c31.

    What Was Covered

    • OK: Original DATE/TIME/DATETIME literal examples; direct ~, ~(operand & -1) and explicit SIGNED cast returned identical expected values.
    • OK: DATE, DATETIME, TIME and TIMESTAMP columns, NULL, fractional rounding boundaries, negative TIME, zero temporal defaults, and TIMESTAMP conversion under +00:00, +08:00, and -05:00, at all three endpoints.
    • OK: Native binary prepared ~? reused with DATE, DATETIME, TIME, fractional TIME, NULL and another DATE; all endpoints and both SQL modes.
    • OK: Integer, text, binary and BIT controls; binary/non-temporal defaults retained their expected values. Unsupported vector input still returned 20203; connections stayed usable.
    • OK: Existing targeted planner tests, including historical unary-NOT table-default fixtures and prepared specialization, passed. Existing temporal_numeric_consumer BVT passed 64/64 including JDBC metadata. MOTR record and replay each passed 24/24 statements.
    • Failed: Five neighboring BVTs passed 405/430 with metadata checking, with 25 metadata expectation differences outside the unary-temporal cases. A separate result-only rerun passed 430/430; this does not count those metadata checks as passing or establish their root cause. No expected results were changed.
    • Not covered: Full repository BVT/SCA and a live upgrade/dump-load round trip. 4.2-dev was 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 timedelta diagnostic 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_not on MOTR main, source c179721d9fec022a536db3f95271d52d49f9720f, daily cherry-pick fd2406b3, in MOTR #389. Record and replay ran with -j 1 and passed.

    Final Conclusion

    The reported bug is verified fixed in the tested main build. Neighboring metadata differences remain explicitly outside the passing test claims.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions