Repository navigation
[4.2] fix: preserve zonemap pruning for DATETIME/TIMESTAMP comparisons - #27097
Merged
XuPeng-SH merged 2 commits intoAug 13, 2026
Merged
Conversation
…rixorigin#26918) - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring issue matrixorigin#26741 Related design discussion: matrixorigin#26775 Mixed `DATETIME`/`TIMESTAMP` comparisons previously cast the `DATETIME` operand to `TIMESTAMP`. For predicates such as `system.statement_info.request_at > DATE_SUB(NOW(), INTERVAL 1 HOUR)`, that wrapped the column in a cast and prevented storage pruning from seeing the raw `DATETIME` column. This PR keeps public result types unchanged and adds direct cross-type comparison support for comparison operators and `BETWEEN`. Column-to-runtime-constant predicates retain the raw column for pruning, while non-constant operands are normalized to one physical `TIMESTAMP` key domain so hash joins, shuffle keys, and runtime filters remain correct. Both zonemap paths now use the session time zone and preserve the established `BETWEEN` precision contract. Conversion is used only when it is order-preserving; ranges that intersect a DST fold or gap fail open and remain for residual evaluation. The readutil fast path also avoids raw-byte comparisons and bloom lookups across the two physical temporal encodings. The base primary-key byte filter has no session-time-zone context, so mixed `DATETIME`/`TIMESTAMP` predicates now fail open there and are evaluated by the residual expression instead of comparing incompatible physical encodings. This applies to both workspace and persisted primary-key reads. Validation covers fixed-offset and named time zones, DST fold/gap counterexamples, differing `BETWEEN` bound scales, NULLs, binder/plan shape, join-key correctness, both zonemap paths, workspace and persisted primary-key reads, full owning-package tests, `go vet`, a full build, direct SQL reproductions, and the local `func_datetime_timezone` BVT (61/61). --------- Co-authored-by: XuPeng-SH <[email protected]> (cherry picked from commit dcef98c)
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? |
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:
issue #26741
Related design discussion: #26775
What this PR does / why we need it:
Backport of #26918 to 4.2-dev.
Mixed DATETIME/TIMESTAMP comparisons previously cast the DATETIME operand to TIMESTAMP. Predicates such as system.statement_info.request_at > DATE_SUB(NOW(), INTERVAL 1 HOUR) therefore wrapped the column in a cast and prevented storage pruning from seeing the raw DATETIME column.
This change keeps public result types unchanged and adds direct cross-type comparison support for comparison operators and BETWEEN. Column-to-runtime-constant predicates retain the raw column for pruning, while non-constant operands are normalized to one physical TIMESTAMP key domain for joins, shuffle keys, and runtime filters.
4.2-dev predates the zonemap helper refactor used by main, so the backport implements the same timezone-aware, fail-open temporal matching contract on the branch's existing zonemap API instead of pulling in unrelated decimal-filter changes.
Validation: