Skip to content

fix: preserve instant in transaction timestamp conversion - #27636

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/ts-to-time-absolute-instant
Aug 26, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/ts-to-time-absolute-instant

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Aug 26, 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:

Fixes #27637

What this PR does / why we need it:

A transaction TS physical component is Unix nanoseconds for an absolute HLC instant. The previous ts_to_time and CAST(TS AS TIMESTAMP) paths formatted that instant as a UTC wall-clock string and reparsed it in the session time zone, shifting the underlying instant by the zone offset and allocating/parsing a string for every row.

This PR converts the HLC physical component directly for both public conversion paths, ignores the non-SQL logical component, validates the original int64 precision before narrowing, and closes NULL handling. Existing TS-to-NOW coverage is retained. The metadata_scan BVT adds CAST/function equivalence and epoch invariance across +08:00 and -05:00 without new fixtures, data loads, sleeps, or cluster initialization.

Validation

  • owning package full UT: mo-cgo-test ./pkg/sql/plan/function -count=1 -timeout=20m — PASS, 12.285s
  • focused UT after rebase to current main — PASS
  • go list, go build, and go vet for ./pkg/sql/plan/function — PASS
  • real candidate service on 10.222.1.55: metadata_scan executed the added function, CAST, NULL, and cross-time-zone epoch checks without unexpected errors
  • benchmark: direct conversion 5.44-5.46 ns/op, 0 B/op, 0 allocs/op; legacy string round trip 181.9-185.9 ns/op, 32 B/op, 1 alloc/op

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

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed exact head c13c617. The direct HLC physical-nanosecond conversion correctly preserves the absolute TIMESTAMP instant for both ts_to_time and CAST, ignores the logical component, closes NULL handling, and validates precision before narrowing. Focused exact-head tests passed; CI executed table_func_metadata_scan.sql with 67/67 assertions, including cross-time-zone epoch invariance. No blocking correctness, compatibility, or regression issue found.

@XuPeng-SH
XuPeng-SH merged commit 8e616a6 into matrixorigin:main Aug 26, 2026
15 of 18 checks passed
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#27636)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#27637

## What this PR does / why we need it:

A transaction TS physical component is Unix nanoseconds for an absolute
HLC instant. The previous `ts_to_time` and `CAST(TS AS TIMESTAMP)` paths
formatted that instant as a UTC wall-clock string and reparsed it in the
session time zone, shifting the underlying instant by the zone offset
and allocating/parsing a string for every row.

This PR converts the HLC physical component directly for both public
conversion paths, ignores the non-SQL logical component, validates the
original int64 precision before narrowing, and closes NULL handling.
Existing TS-to-NOW coverage is retained. The metadata_scan BVT adds
CAST/function equivalence and epoch invariance across +08:00 and -05:00
without new fixtures, data loads, sleeps, or cluster initialization.

## Validation

- owning package full UT: `mo-cgo-test ./pkg/sql/plan/function -count=1
-timeout=20m` — PASS, 12.285s
- focused UT after rebase to current main — PASS
- `go list`, `go build`, and `go vet` for `./pkg/sql/plan/function` —
PASS
- real candidate service on `10.222.1.55`: metadata_scan executed the
added function, CAST, NULL, and cross-time-zone epoch checks without
unexpected errors
- benchmark: direct conversion 5.44-5.46 ns/op, 0 B/op, 0 allocs/op;
legacy string round trip 181.9-185.9 ns/op, 32 B/op, 1 alloc/op

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#27636)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#27637

## What this PR does / why we need it:

A transaction TS physical component is Unix nanoseconds for an absolute
HLC instant. The previous `ts_to_time` and `CAST(TS AS TIMESTAMP)` paths
formatted that instant as a UTC wall-clock string and reparsed it in the
session time zone, shifting the underlying instant by the zone offset
and allocating/parsing a string for every row.

This PR converts the HLC physical component directly for both public
conversion paths, ignores the non-SQL logical component, validates the
original int64 precision before narrowing, and closes NULL handling.
Existing TS-to-NOW coverage is retained. The metadata_scan BVT adds
CAST/function equivalence and epoch invariance across +08:00 and -05:00
without new fixtures, data loads, sleeps, or cluster initialization.

## Validation

- owning package full UT: `mo-cgo-test ./pkg/sql/plan/function -count=1
-timeout=20m` — PASS, 12.285s
- focused UT after rebase to current main — PASS
- `go list`, `go build`, and `go vet` for `./pkg/sql/plan/function` —
PASS
- real candidate service on `10.222.1.55`: metadata_scan executed the
added function, CAST, NULL, and cross-time-zone epoch checks without
unexpected errors
- benchmark: direct conversion 5.44-5.46 ns/op, 0 B/op, 0 allocs/op;
legacy string round trip 181.9-185.9 ns/op, 32 B/op, 1 alloc/op

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#27636)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#27637

## What this PR does / why we need it:

A transaction TS physical component is Unix nanoseconds for an absolute
HLC instant. The previous `ts_to_time` and `CAST(TS AS TIMESTAMP)` paths
formatted that instant as a UTC wall-clock string and reparsed it in the
session time zone, shifting the underlying instant by the zone offset
and allocating/parsing a string for every row.

This PR converts the HLC physical component directly for both public
conversion paths, ignores the non-SQL logical component, validates the
original int64 precision before narrowing, and closes NULL handling.
Existing TS-to-NOW coverage is retained. The metadata_scan BVT adds
CAST/function equivalence and epoch invariance across +08:00 and -05:00
without new fixtures, data loads, sleeps, or cluster initialization.

## Validation

- owning package full UT: `mo-cgo-test ./pkg/sql/plan/function -count=1
-timeout=20m` — PASS, 12.285s
- focused UT after rebase to current main — PASS
- `go list`, `go build`, and `go vet` for `./pkg/sql/plan/function` —
PASS
- real candidate service on `10.222.1.55`: metadata_scan executed the
added function, CAST, NULL, and cross-time-zone epoch checks without
unexpected errors
- benchmark: direct conversion 5.44-5.46 ns/op, 0 B/op, 0 allocs/op;
legacy string round trip 181.9-185.9 ns/op, 32 B/op, 1 alloc/op

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

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 kind/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TS to TIMESTAMP conversion changes the absolute instant with session time zone

3 participants