Skip to content

[4.2] fix: preserve zonemap pruning for DATETIME/TIMESTAMP comparisons - #27097

Merged
XuPeng-SH merged 2 commits into
matrixorigin:4.2-devfrom
aptend:backport/4.2-26918-temporal-pruning
Aug 13, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:4.2-devfrom
aptend:backport/4.2-26918-temporal-pruning

Conversation

@aptend

@aptend aptend commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • 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

…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)
@aptend
aptend requested a review from a user August 13, 2026 06:35
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

This branch was previously deployed

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

Labels

kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants