Skip to content

fix(frontend): retain DATETIME fractional width in text rows - #29076

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/issue-28921
Oct 4, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/issue-28921

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Fixes #28921: direct MySQL text rows for exact-second DATETIME(p) omitted the declared fractional width when p > 0.

#28596 was addressed by merged #28851. #28602 remains open and deferred: calendar-invalid DATE/DATETIME input such as 2024-02-30 is still rejected during parsing/assignment, so this PR introduces no such value into comparisons or indexes. The previous ALLOW_INVALID_DATES implementation was removed after storage, index and recovery compatibility review. The zero-DATETIME test below covers the existing zero sentinel.

What changed?

  • Preserve .0, .000, or .000000 for exact-second DATETIME(p) text output. The fast path caps malformed scale at 9, matching the existing nonzero-fraction formatter bound.
  • Assert raw MySQL text and prepared binary row packets for ordinary and zero DATETIME(6) values; keep focused scale and nonzero-fraction controls.

Validation

Base: main at 5a96035fc7 (includes #28851). The rebase added only #29411's unrelated transaction BVT files.

  • Focused CGo pkg/frontend tests TestColumnSlicesGetDatetime and TestDatetimeExactSecondWireRowsKeepDeclaredScale: passed after final code change.
  • go vet -mod=readonly ./pkg/frontend: passed. golangci-lint v2.6.2 / Go 1.26.4 on ./pkg/frontend: 0 issues. gofmt and git diff --check: clean.
  • Existing distributed datetime_precision_comprehensive.sql BVT on the local built service: 91/91 passed before the final equivalent zero-fraction fast-path refinement; direct MySQL CLI observed expected p0/p3/p6 text output. The raw packet tests above validate the final code path.
  • Independent review of the final three-file diff found no blockers; it checked formatting, protocol bytes, cleanup, scale bound and hot-path cost.

CI is not claimed as passed here. No persisted format, SQL mode, protocol epoch or cross-CN behavior changes are included.

@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/S Denotes a PR that changes [10,99] lines label Sep 18, 2026
@jiangxinmeng1 jiangxinmeng1 changed the title fix(frontend): preserve DATETIME fractional scale in text output fix(temporal): honor compatible DATE/DATETIME semantics Sep 18, 2026
@jiangxinmeng1 jiangxinmeng1 changed the title fix(temporal): honor compatible DATE/DATETIME semantics fix(temporal): honor compatible date and week semantics Sep 18, 2026
@matrix-meow matrix-meow added size/XL Denotes a PR that changes [1000, 1999] lines and removed size/S Denotes a PR that changes [10,99] lines labels Sep 18, 2026

@aptend aptend 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.

Reviewed exact head ad5dff9, including the full diff and all prior review history. The earlier persisted-dedup ordering, remote WEEK mode, and LAST_DAY/foldability concerns are addressed, but the current head still has execution-time temporal regressions and fails its own UT/BVT coverage. Focused temporal/type/vector/process/storage tests pass; the two exact planner tests fail locally as in CI.

Comment thread pkg/sql/plan/build_constraint_util.go Resolved
Comment thread pkg/sql/plan/function/func_cast.go Resolved
Comment thread pkg/sql/plan/build_constraint_util.go Resolved

@aptend aptend 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.

Re-reviewed the full diff and the increment since my previous review at ad5dff9df79fcc9e454164985411e949c5615a48, including all historical reviews, replies, and resolved threads. The five issues from that review now appear addressed, and the focused temporal/planner/process/TAE tests pass on this exact head. Two new P1 blockers remain:

  1. The new negative tagged DATE/DATETIME values are persisted and transferred as ordinary fixed-width vector values without a storage/wire version or rollout gate. An old CN can read data written by a new CN during a rolling upgrade and silently return corrupt temporal values.
  2. Calendar comparison was changed, but tuple encoding still calls Packer.EncodeDate/EncodeDatetime, which encodes the raw signed integer. This disagrees with the new semantic order and makes composite-PK/secondary-index range scans under-fetch invalid dates.

Exact head reviewed: eb39b3baba566c03676e532aa230ddcf0a36b6bb.

Comment thread pkg/container/types/date.go Resolved
Comment thread pkg/container/types/compare.go Resolved

@aptend aptend 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.

Re-reviewed the full diff and the complete review/thread history at exact head 3a2dd1a82be5440395237d65818659b409978ba6, with special attention to the two-commit increment since my prior review at eb39b3baba566c03676e532aa230ddcf0a36b6bb. The increment only changes explicit-cast selection and DATE/DATETIME cast-mode handling; it does not close either previously reported P1. It also introduces a third P1 demonstrated by the current-head PROXY BVT. Requesting changes until all three paths are fixed and covered.

Comment thread pkg/sql/plan/base_binder.go Resolved
Comment thread pkg/container/types/date.go Resolved
Comment thread pkg/container/types/compare.go Resolved

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

REQUEST_CHANGES

P1 — Tagged temporal values break ordering and persisted-value compatibility

The new negative DATE/DATETIME tags change the stored scalar representation (date.go). SQL comparisons use calendar fields, while tuple/index keys encode the raw signed integer; for an allowed invalid date, the encoded key order can be opposite to SQL date order, causing incorrect index/range results. The raw value is also persisted without a format/version discriminator, so binaries predating this change silently decode newly written invalid dates as different calendar values. Please provide an ordering-compatible encoding and an enforceable mixed-version/rollback compatibility plan.

P2 — Prepared binary SELECT rejects a value accepted on write

With ALLOW_INVALID_DATES, an invalid DATETIME can be stored, but the prepared-statement binary result path reparses its formatted value using the strict parser (mysql_protocol.go). COM_STMT_EXECUTE/COM_STMT_FETCH then returns an error instead of the stored row. Encode the stored calendar fields directly and cover this protocol path.

P2 — Required design approval is not linked

This changes persisted scalar semantics, ordering, and compatibility, triggering the design gate. The PR does not link an exact reviewed design revision; please provide the approved design and rollout/rollback decision.

@jiangxinmeng1

Copy link
Copy Markdown
Contributor Author

Addressed the exact-head review findings in 7e05e33.\n\n- DATE/DATETIME tuple/index encoding now uses dedicated calendar-order keys and round-trips tagged invalid fields.\n- ColumnData V3 is emitted only for columns containing tagged invalid DATE/DATETIME values; V1/V2 remain unchanged, and old readers fail closed on V3.\n- Prepared binary DATETIME results encode stored calendar fields directly instead of formatting and reparsing with strict ParseDatetime.\n- Added focused tuple, ColumnData, and binary-protocol regressions.\n- Design/rollout/rollback RFC: https://github.com/jiangxinmeng1/matrixone/blob/7e05e33e238f9f3b39b1b6ee7d04bde887d6dd16/docs/rfcs/20260924_invalid_temporal_storage_compatibility.md\n\nRemote validation on 10.222.1.55:\n- CGo UT: pkg/container/types, pkg/objectio, pkg/frontend passed.\n- Focused temporal tuple/objectio/binary protocol tests passed.\n- Incremental go vet passed with the repository CGo include paths.\n- make cgo completed; the worktree emitted only the existing “no tag exactly matches” version-info warning.\n- Full mixed-version/upgrade validation remains a release gate described in the RFC and requires design approval before enabling tagged-value persistence.

@jiangxinmeng1

Copy link
Copy Markdown
Contributor Author

Follow-up CI fix pushed as 6a1b5d7.\n\nThe failed coverage UT was PR-introduced: databranchutils.TestEncodeRowCoversManyTypes relied on Packer DATE/DATETIME preserving arbitrary raw in-memory scalars. The ordered temporal key path now preserves those legacy raw values in a reserved non-SQL key range while keeping canonical SQL temporal values calendar-ordered.\n\nRemote 55 validation passed:\n- pkg/container/types focused temporal and existing tuple tests\n- pkg/frontend/databranchutils TestEncodeRowCoversManyTypes and related tests\n\nCompose/Standalone BVT failures were connection-loss cascades (mo-tester can not get valid connection), and Coverage merge was blocked by the failed UT producer. No upstream merge was needed because the actionable UT failure was introduced by this PR. New CI: https://github.com/matrixorigin/matrixone/actions/runs/35973524019

@jiangxinmeng1

Copy link
Copy Markdown
Contributor Author

Follow-up CI fix pushed as 6a1b5d7.\n\nThe failed coverage UT was PR-introduced: databranchutils.TestEncodeRowCoversManyTypes relied on Packer DATE/DATETIME preserving arbitrary raw in-memory scalars. The ordered temporal key path now preserves those legacy raw values in a reserved non-SQL key range while keeping canonical SQL temporal values calendar-ordered.\n\nRemote 55 validation passed:\n- pkg/container/types focused temporal and existing tuple tests\n- pkg/frontend/databranchutils TestEncodeRowCoversManyTypes and related tests\n\nCompose/Standalone BVT failures were connection-loss cascades (mo-tester could not get a valid connection), and Coverage merge was blocked by the failed UT producer. No upstream merge was needed because the actionable UT failure was introduced by this PR.\n\nNew CI: https://github.com/matrixorigin/matrixone/actions/runs/35973524019

@fengttt fengttt 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.

explain to me how we get an invalid date in the first place. should it ever reach compare? why didn't we catch the invalidness when the data is inserted or parsed from sql statement?

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

Reviewed head 2c9f06ff316383c4e83611634d0b0f8178c40636 against base 5a96035fc792b07b7a28e2f509dc0dcd4236e048, including all three changed files and the previous reviews/inline comments. No blocking findings for the current scope; APPROVE.

The remaining change fixes #28921 at the shared vector-to-MySQL formatting boundary: exact-second DATETIME(p) retains its declared fractional width. I traced text output, prepared execution/cursor binary output, metadata-type fallbacks, NULL handling, constant vectors, zero DATETIME, nonzero fractions, scale 0 and malformed large scale. The new raw-packet test distinguishes the original defect and verifies unchanged binary bytes. Test cleanup is scoped and bounded. This is an ordinary local bug fix; a persisted-format design gate is no longer applicable.

The earlier invalid-calendar storage/index, assignment/folding and mixed-version findings concern code removed from this PR. #28602 remains open and deferred, not fixed. The WEEK implementation is inherited from merged #28851. The current diff introduces no stored representation or cross-CN protocol change.

Validation: newly ran the entire pkg/frontend package at this head through the repository CGo wrapper (-count=1 -timeout=300s): PASS, 36.960 s. Reused the semantically unchanged focused raw-packet/formatting tests, frontend vet/lint (0 issues), and local precision BVT (91/91); the BVT preceded the equivalent final fast-path refinement, while the package run above includes the final code. JDBC normalization makes that BVT insufficient alone for fractional-width correctness; the raw byte assertions supply that oracle. No new shared state or synchronization is introduced, so an additional race run is not required for this closure.

Performance: a local formatter microbenchmark measured old scale-0 formatting at 252.5 ns / 2 allocs, the selected scale-6 suffix form at 281.1 ns / 3 allocs, and full String2(6) at 387.1 ns / 4 allocs. The extra bounded allocation is a real cost for corrected exact-second output; these are formatter measurements, not an end-to-end throughput claim. No new I/O, locks, workers or retained state are added, and no broader refactor is warranted here.

CI is still running and was not awaited; this approval does not replace required CI or other reviewers' decisions.

@XuPeng-SH

Copy link
Copy Markdown
Contributor

@fengttt Thanks for calling this out. In the earlier #29076 draft, ALLOW_INVALID_DATES was intended to allow values such as 2024-02-30 at conversion/assignment time. Once stored, those values would have to participate in comparisons for ORDER BY, predicates, primary keys and indexes. The draft did not close the required storage and index compatibility paths, so we removed that feature from this PR.

At the current head (2c9f06ff31), calendar-invalid DATE/DATETIME input is still rejected during parsing/assignment; it cannot reach comparison through this change. Full support is tracked separately in #28602 and is deferred. This PR only fixes the declared fractional width when returning an existing DATETIME value. Its zero-DATETIME test covers the pre-existing zero sentinel, not a newly accepted date such as February 30.

@fengttt fengttt 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.

Don't you want a bvt test?

@aptend aptend 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.

Reviewed exact head 856ba5761175b1851dc98bb454957b1aaab2610d against base 0782fafc3efd01eca0d78fa3701d74eb5b7b0eaa, the complete three-file diff, prior reviews, inline threads, author replies, and the increment from the prior invalid-calendar scope. No blocking finding in the current change. ColumnSlices.GetDatetime now preserves the declared width for exact-second DATETIME(p), including the zero sentinel; p=0 and nonzero fractions retain their existing path, and malformed p>9 is bounded. I traced text COM_QUERY and prepared binary COM_STMT_EXECUTE output. The raw-packet unit test asserts the exact 26-byte DATETIME(6) text payload and unchanged binary payload; the exact-head focused frontend tests pass locally (TestColumnSlicesGetDatetime, TestDatetimeExactSecondWireRowsKeepDeclaredScale), and current-head CI UT/coverage/BVT are green. The old invalid-date storage/index and compatibility objections are no longer in this PR. On the BVT request: the existing datetime_precision_comprehensive BVT runs successfully, but its JDBC-rendered result normalizes away trailing zero precision (its expected CAST-to-DATETIME(6) output is 2024-01-15 12:34:56), so it cannot distinguish this wire-format regression. The new raw-packet assertion does distinguish it; a BVT using a raw MySQL client could be added separately.

@jiangxinmeng1

jiangxinmeng1 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Don't you want a bvt test?

Added BVT coverage in commit b58e01cef9:

  • Extended the existing datetime_precision_comprehensive case with a focused exact-second and zero DATETIME(6) table/query over the real SQL/frontend path.
  • Added the matching result oracle and kept the fixture self-contained with explicit cleanup.
  • The frontend raw-packet UT remains the byte-level oracle because mo-tester/JDBC normalizes trailing-zero fractional digits when rendering DATETIME results.

The BVT is complementary end-to-end coverage; it does not replace the precise protocol-packet assertion.

@fengttt

fengttt commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

explain to me how we get an invalid date in the first place. should it ever reach compare? why didn't we catch the invalidness when the data is inserted or parsed from sql statement?

@jiangxinmeng1 @XuPeng-SH #28602 should NOT be implemented at all. I don't understand what is the point ...

@jiangxinmeng1

Copy link
Copy Markdown
Contributor Author

explain to me how we get an invalid date in the first place. should it ever reach compare? why didn't we catch the invalidness when the data is inserted or parsed from sql statement?

You are right to question this.

The invalid-date path came from the earlier implementation for #28602. It intentionally allowed values such
as 2024-02-30 under ALLOW_INVALID_DATES, so those values could be stored and later reach comparison. That
behavior requires a complete design for comparison, index/tuple encoding, persistence, and mixed-version
compatibility.

We have removed that behavior from this PR. At the current head, ParseDateCast and ParseDatetime reject non-
zero invalid calendar dates through ValidDate. The only accepted special case is the existing zero temporal
sentinel (0000-00-00), which is different from 2024-02-30 and is not introduced by this fix.

Therefore, an invalid date such as 2024-02-30 should not reach comparison through the normal SQL parse/
insert path in this PR. The added BVT only covers the existing zero-DATETIME wire representation. Support
for non-zero invalid dates remains deferred to #28602 and should only be implemented with an end-to-end
storage and comparison design.

@aunjgr aunjgr 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.

Reviewed 71748a6. The change is confined to exact-second DATETIME text formatting; scale 0 and nonzero fractions retain the existing path. Raw protocol tests distinguish text rows from binary prepared rows, including zero DATETIME, and CI is green. No blocking issue found.

@mergify

mergify Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

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

APPROVE — re-reviewed exact head c3edf19 against base/merge-base 205b06f. No blocking findings in the current five-file change.

Design and responsibility: this is now a focused #28921 output-contract fix in ColumnSlices.GetDatetime, not an invalid-calendar feature. Keeping the correction at the existing vector-to-MySQL formatting owner is appropriate. The bounded exact-second suffix preserves declared precision without adding another parser, state machine, persistent representation, or execution path. The incorrect old MySQL-behavior comment is removed. This ordinary bug fix does not need the earlier persisted-format design gate.

QA challenge: traced direct text output, prepared execution and cursor binary output, DATETIME vectors under DATE/TIMESTAMP/VAR_STRING metadata, constant-vector row remapping, NULL short-circuiting, zero sentinel versus the year-1 epoch, scale 0, nonzero fractions and the scale bound. The binary consumer reparses the corrected string and still emits the same date/time bytes; the new byte-level test covers ordinary and zero DATETIME(6). Error propagation and packet/allocator ownership are unchanged. The new tests register cleanup immediately and add no service, wall-clock wait, or shared global fixture.

Historical comments: inspected all review bodies, issue comments and all 10 inline threads. The tagged invalid-date storage/index/assignment/folding objections are closed by removal of that implementation, not by claiming #28602 is fixed; it remains deferred. Those production areas and docs have no delta against this base. The WEEK-related work is inherited from main. The requested BVT is now present and executed. Its JDBC-rendered oracle normalizes trailing zeros, so it is complementary SQL-path coverage, not the proof of fractional width; the raw-packet UT is the discriminating oracle.

Validation: reused completed exact-head CI run 37145836917, not just its aggregate badge. The UT checkpoint explicitly includes pkg/frontend in the race-enabled light phase, which ends with status 0; the non-race coverage UT and SCA jobs also succeed. The downloaded pessimistic BVT execution report names datetime_precision_comprehensive.sql: 99/99 passed, 0 ignored, 0 abnormal (0.811 s). Local gofmt and diff-whitespace checks pass. A local focused CGo test attempt stopped before compilation because this isolated worktree lacks matching native artifacts and primary-worktree reuse was rejected; it is NOT counted as a test pass. No additional CI run was awaited.

Engineering/performance: production +4/-2, tests and result fixtures +152/-1, repository docs unchanged. The additional tests provide distinct formatting, exact-wire/binary-control, and SQL integration oracles. Exact-second positive-scale output now pays for a bounded suffix allocation and up to 10 additional text bytes; prepared output also reparses that fraction. This is a correctness cost, not a throughput optimization. Other formatter branches are unchanged, with no new I/O, locks, workers, or retained state. No persisted-data migration or mixed-upgrade mechanism is introduced. I found no justification for broadening this small fix into a formatter/protocol refactor.

This branch was previously deployed

1 inactive deployment
ci — 6ac7ef8a Deployed Oct 4, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compatibility]: DATETIME(p) exact-second text output omits declared fractional width

6 participants