Repository navigation
fix: correct temporal numeric coercion for bit consumers - #32642
Merged
mergify[bot] merged 6 commits intoNov 17, 2026
Merged
Conversation
Convert DATE, DATETIME, TIME, and TIMESTAMP through their numeric semantics for bitwise operators, BIT_COUNT, and SEC_TO_TIME. Preserve native temporal conversion across prepared numeric latches while keeping string and binary behavior unchanged. Add planner, SQL, and native-protocol regressions for literals, columns, fractions, warnings, prepared reuse, and NULL handling. Related to matrixorigin#31904.
Keep BIT_COUNT's dedicated prepared fallback marker out of the generic numeric collector. Include the dedicated positions in native temporal packet decoding, using current metadata when a prepared plan is rebuilt.
1 task done
Contributor
Author
|
CI triage for
The UT blocker remains unresolved. Attempt 2 was the single permitted rerun, so no further rerun was requested. No PR code or tests were changed for this disposition. |
Contributor
✅ Merged into
|
1 task done
1 of 7 tasks
XuPeng-SH
pushed a commit
that referenced
this pull request
Nov 20, 2026
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #32873 ## What this PR does / why we need it: Unary bitwise NOT (`~`) rejected native DATE, TIME, DATETIME and TIMESTAMP operands: ```sql SELECT ~CAST('2024-06-18' AS DATE); -- ERROR 20203 (HY000): invalid argument operator unary_tilde, bad value [DATE] ``` ### Root cause #32642 made the native temporal-to-integer conversion a per-parameter contract (`integerParameters` with `temporalOnlyIntegerParameter`). That declaration drives both argument-type normalization (`checkArgumentTypes`) and the binder's `appendSourceDependentIntegerArgument`, which inserts `TemporalIntegerArgumentCastOverload`. It was added to `&`, `|`, `^`, `<<`, `>>` and `BIT_COUNT`, but not to `UNARY_TILDE`. For `~`, `unaryTildeTypeMatch` only adds an implicit cast for CHAR/VARCHAR/TEXT, so a temporal operand fell through to direct overload matching and was rejected. ### Fix Declare `integerParameters: {{position: 0, mode: temporalOnlyIntegerParameter}}` on `UNARY_TILDE`. No new mechanism is needed. For any non-temporal source, `sourceTarget` reports "not applicable", so integer, text, binary and BIT behavior is unchanged. ### Validation - The new planner UTs fail on the base commit with `invalid argument operator unary_tilde, bad value [DATE|DATETIME|TIME|TIMESTAMP]` and pass with the fix. They cover literals, columns (NULL, zero value, negative and fractional TIME, TIMESTAMP in UTC), a prepared `~?` with native temporal parameters and template reuse, and integer/text controls. - BVT `temporal_numeric_consumer` is extended with `~` cases, including the equivalence from the issue (`~(d & -1) = ~CAST(d AS SIGNED) = 18446744073689310997`). `.result` was generated by mo-tester against a locally built standalone service. The case passes 60/60. Related cases also pass: `func_bit_count` 210/210, `mysql_compat_temporal_numeric_cast` 30/30, `bit_integer_parameter_coercion` 47/47, `integer_parameter_coercion` 118/118, `mysql_compat_bitwise_expr` 25/25. - Go packages `./pkg/sql/plan` and `./pkg/sql/plan/function` pass in full, and so does `TestTypeSwitchFamilies`. `go vet` and incremental `golangci-lint` report no issues. - Not run locally: the full BVT suite and repository-wide SCA, which are left to CI. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2 of 4 tasks
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
Related to #31904.
What this PR does / why we need it:
Temporal values reached integer consumers through string/provisional domains. As a result,
&,|, and^could return 255-byte binary strings for DATE/DATETIME/TIME instead of the numeric results returned by MySQL. BIT_COUNT and SEC_TO_TIME also lacked complete native temporal conversion and prepared rebinding behavior.Root causes
Changes
&,|,^,<<,>>, and BIT_COUNT while preserving existing numeric, text, plain-hexadecimal, and explicit-binary behavior.The original row now produces
d & 3 = 1,dt | 1 = 20240101100001,tm ^ 1 = 10202, andd << 1 = 40480202. On one prepared cursor, DOUBLE64.0, native TIME00:00:00.500000, and native DATETIME2024-02-29 23:59:59.500000now produce BIT_COUNT values1,1, and20; later text2024-01-01produces7with warning 1292, and NULL produces NULL without a warning.Issue-to-test proof
0c8bd5e5f3be4ce5582201513161181ddca37d6d, the focused temporal UT failed all nine primary witnesses. The same coverage passes after the change. The prepared mixed-text regression also failed on base and passes after the prepared binding repair.0instead of1and DATETIME25instead of20; the identical UT and native-protocol probe pass after the repair.TestTypeSwitchFamiliesinitially identified the two new partial switches and passes after concretetypeswitch:partialannotations, without expanding its baseline.43222436235passed all 12 valid cases. The final numeric-to-temporal prepared sequence has additional focused UT and canonical native-protocol proof.c4081ad46b595a64eba59c78aeefe90d8642606a, the UT Coverage regression expected generic numeric positions[0]but observed[0,1]. The identical frontend test now passes with generic positions[0], dedicated BIT_COUNT positions[1], and temporal runtime positions[0,1]; eight related frontend tests and the complete planner package also pass.temporal_numeric_consumer57/57 twice,func_bit_count210/210,func_datetime_sec_to_time33/33,mysql_compat_temporal_numeric_cast30/30,temporal_numeric_zero_default_2972118/18,func_temporal_consistency_28851458/458,integer_parameter_coercion118/118,bit_integer_parameter_coercion47/47, andmysql_compat_bitwise_expr25/25.Validation commands
The final complete planner package passed in 176.570s, the function package passed in 49.541s, the build and both static checks exited 0, and incremental lint reported
0 issues.The CI metadata repair passed its exact frontend regression, eight related frontend tests, the complete planner package in 99.596s, and
go vetfor the planner and frontend packages.Base refresh merge
16f7b4c94044c3752471b2c1257768b820d9e6dfincorporatesmainthroughf491aaab4519b29313c5747d3ce3b3f84e865c71. Both focused planner selections above passed at that merge head, including the prepared-CRC32 controls sharingResetParamRefRule; the PR diff remains scoped to the same 17 files andgit diff --checkpasses.Residual risks and limitations
datetime.timedeltaverification uses the pure encoder (use_pure=Trueor a pure-only installation); the optional 9.4.0 C encoder emits malformed prepared TIME payloads.