Repository navigation
fix: preserve zonemap pruning for DATETIME/TIMESTAMP comparisons - #26918
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.
Deep review completed. I traced the mixed DATETIME/TIMESTAMP contract through binder normalization, scalar comparisons and BETWEEN, hash/shuffle key typing, colexec zonemap folding, readutil object/block filtering, and the PK byte-filter fallback. The implementation preserves the prior TIMESTAMP-scale semantics, propagates the session time zone where pruning needs it, and fails open for DST folds/gaps or paths without time-zone context; I did not find a false-negative pruning or physical-key mismatch counterexample.
I also verified the exact head (3bb09e4) with diff/gofmt checks and focused CGo-controlled tests for types, function execution, planner shape, colexec zonemaps, readutil filtering, and mixed temporal PK handling. All passed.
#27097) ## 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 #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: - GOWORK=off go build -mod=readonly ./pkg/container/types ./pkg/sql/colexec ./pkg/sql/plan ./pkg/sql/plan/function ./pkg/vm/engine/readutil ./pkg/vm/engine/disttae - GOWORK=off go vet -mod=readonly ./pkg/container/types ./pkg/sql/colexec ./pkg/sql/plan ./pkg/sql/plan/function ./pkg/vm/engine/readutil ./pkg/vm/engine/disttae - focused DATETIME/TIMESTAMP comparison, binder, zonemap, and readutil regression tests - full owning-package tests for all six packages above Co-authored-by: XuPeng-SH <[email protected]>
…rixorigin#26918) ## 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 matrixorigin#26741 Related design discussion: matrixorigin#26775 ## What this PR does / why we need it: 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]>
…rixorigin#26918) ## 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 matrixorigin#26741 Related design discussion: matrixorigin#26775 ## What this PR does / why we need it: 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]>
…rixorigin#26918) ## 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 matrixorigin#26741 Related design discussion: matrixorigin#26775 ## What this PR does / why we need it: 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]>
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:
Mixed
DATETIME/TIMESTAMPcomparisons previously cast theDATETIMEoperand toTIMESTAMP. For predicates such assystem.statement_info.request_at > DATE_SUB(NOW(), INTERVAL 1 HOUR), that wrapped the column in a cast and prevented storage pruning from seeing the rawDATETIMEcolumn.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 physicalTIMESTAMPkey domain so hash joins, shuffle keys, and runtime filters remain correct.Both zonemap paths now use the session time zone and preserve the established
BETWEENprecision 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/TIMESTAMPpredicates 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
BETWEENbound 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 localfunc_datetime_timezoneBVT (61/61).