Skip to content

fix: preserve zonemap pruning for DATETIME/TIMESTAMP comparisons - #26918

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
aptend:fix/temporal-cross-type-pruning
Aug 10, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
aptend:fix/temporal-cross-type-pruning

Conversation

@aptend

@aptend aptend commented Aug 10, 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:

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).

@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 →

@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Aug 10, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Aug 10, 2026
@aptend
aptend requested a review from gouhongshen as a code owner August 10, 2026 09:03
@aptend
aptend requested a review from a user August 10, 2026 09:03
@matrix-meow matrix-meow added size/XL Denotes a PR that changes [1000, 1999] lines and removed size/L Denotes a PR that changes [500,999] lines labels Aug 10, 2026

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@XuPeng-SH
XuPeng-SH merged commit dcef98c into matrixorigin:main Aug 10, 2026
22 of 25 checks passed
XuPeng-SH added a commit that referenced this pull request Aug 13, 2026
#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]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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]>

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