Skip to content

fix: align date compatibility semantics - #28851

Merged
XuPeng-SH merged 61 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/date-compatibility-batch-20260914
Sep 27, 2026
Merged

XuPeng-SH merged 61 commits into
matrixorigin:mainfrom
jiangxinmeng1:codex/date-compatibility-batch-20260914

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Test and CI

Which issue(s) this PR fixes:

Related reports: #28596, #28574, #28573, #28572, #28567, #28566, #28129, #28569, #28559, #28501, #28500, #28151, #28150, #28149, #28147, #28142, #27189, #28498, #28497, #25306, #25307. These are non-closing references; shared validation does not assert independent acceptance of every historical report.

Behavior contract and rationale

This PR defines one MatrixOne temporal contract for newly bound SQL while preserving released 4.2 stored-expression ABI. The complete expected behavior, examples, diagnostic ownership, result types, COM_QUERY/COM_STMT metadata, and upgrade rules are in temporal compatibility design (C01–C42). MySQL 8 is comparative evidence, not the oracle where its behavior is internally inconsistent or conflicts with MatrixOne's released semantics.

Area Main before this PR MySQL 8 reference Expected MatrixOne behavior
TIME and calendar domain Existing TIME endpoint and typed zero-date sentinel; temporal overloads did not consistently enforce the final result domain. TIME endpoint ±838:59:59; permissive arithmetic may saturate. TIME remains a signed duration at that endpoint and FSP 0–6; ordinary calendar years 1–9999. Evaluated DATE_ADD/SUB, ADDTIME/SUBTIME, TIMEDIFF overflow returns row NULL + warning 1441, without premature operand saturation (C01–C07).
Interval classification Compound no-digit text could act as a successful no-op; numeric/text spelling and overload paths diverged. Permissive compound no-op is also observed. No-digit interval text is invalid/NULL; exact numeric values, literal/column/marker paths, and scalar/compound units use the same classification. Released numeric compound grammar remains compatible (C08–C16).
Conversion and empty payloads TIME conversion, assignment, function grammar, and released ordinary empty payload had distinct behavior. Mode-sensitive conversion/assignment differs, including empty text. Keep distinct CAST/TIME()/assignment policies, including 1292 conversion clamp and strict/non-strict write diagnostics; preserve released 4.2 ordinary empty TIME payload→NULL while IGNORE adjusts it explicitly (C30–C35).
Function type and metadata Newly bound EXTRACT/string ADDTIME paths could retain older physical result families; dynamic formats needed consistent binding. Static STR_TO_DATE format determines temporal family; dynamic format resolves to DATETIME(6); result metadata follows bound overload. New EXTRACT is signed BIGINT; string ADDTIME/SUBTIME is VARCHAR(29); static STR_TO_DATE follows known format and dynamic format is DATETIME(6). Persisted 4.2 overload IDs keep their old physical types (C17–C29, C36, C39).
Text/binary prepare and warnings A prepared JOIN diagnostic could block selectivity or be evaluated at the wrong lifecycle point; unrelated runtime markers could discard a valid proof. Used to check protocol/result metadata and diagnostics, not to dictate MatrixOne's warning ownership. COM_QUERY and real COM_STMT_EXECUTE agree on values, warnings, field type/length/decimals/flags and NULL bits. JOIN ON/filters retain one logical diagnostic owner; inactive/empty paths stay silent. Each execution reproves safety after final binding, keeps a conservative fallback, and never publishes the local selective plan into the prepared cache (C06–C07, C36–C38).
Upgrade/placement Release 4.2 advertises MORPC9/10; main's independent decimal division requires MORPC97. No corresponding MatrixOne placement protocol. One final MORPC98 capability gates changed temporal/conversion semantics on placement, transport, and stored-expression admission; restart reconciles missing trace views after authoritative catalog admission. Existing 4.2 stored expressions remain readable (C39–C42).

Latest CI repair (1a5a2a38b5)

The proxy multi-CN BVT job had three deterministic value mismatches. Two exposed an inconsistency: under NO_ZERO_DATE, raw DAYOFMONTH and QUARTER on accepted 0000-00-00 12:34:56 text returned NULL, although typed zero fields and the established BVT expectation were zero. The shared unary helper and new VARCHAR EXTRACT had copied a check owned by explicit DATE conversion. Both checks are removed; parser validation, invalid-week behavior, and DATE/CAST mode policy remain intact. The third mismatch was an obsolete INET_NTOA(TIME '00:00:02.654321') golden: existing numeric TIME coercion rounds to 3, matching MySQL 8.0.46 and the existing boundary test, so the expected address is 0.0.0.3.

Operation Before repair under NO_ZERO_DATE MySQL 8.0.46 reference Expected MatrixOne after repair
Raw YEAR/MONTH/DAY/DAYOFMONTH/QUARTER on accepted zero-date text; corresponding new EXTRACT fields NULL zero zero in both SQL modes, like typed zero fields
YEAR(DATE('0000-00-00')) NULL NULL NULL under NO_ZERO_DATE; zero when DATE construction is allowed
WEEKOFYEAR('0000-00-00') NULL NULL NULL: a week requires a valid calendar
INET_NTOA(TIME '00:00:02.654321') 0.0.0.3 0.0.0.3 0.0.0.3; no production behavior change

The C16/C17 contract and zero-calendar truth table above now state this distinction explicitly. The same prepared query over a VARCHAR column was executed across a mode switch: zero and partial-zero fields, invalid dates, malformed text and invalid-week controls behaved as expected. The complete pkg/sql/plan/function package, owning-package go vet, make err-check, and git diff --check pass. A fresh binary built from this repair passed 630/630 targeted statements across the original three failing scripts, temporal consistency and zero-temporal compatibility BVT with metadata comparison disabled (-n). With metadata comparison enabled, four separate DATE/DATETIME width expectations differ (64 expected versus 10/19 actual); this local replay does not establish whether that discrepancy is baseline-wide, and the cited CI failure contained only the three value mismatches. Full new-head CI remains pending.

Review repair at 9ccb74d984

Prior head: 9ccb74d984ce31f036c4aa41dee32225b157e0ba, rebased onto MatrixOrigin main 50c15c1fd461fc3cd320d047b95ff3316170d468. This update closes review 5326472073 on the original PR:

  1. Prepared JOIN proof now follows final runtime specialization. It probes the conservative template and runtime plan, rebuilds a selective plan only for that execution, then probes the final bound plan before use. Compile retries repeat the proof. Safe→warning→NULL→safe handle reuse keeps results, warning ownership and selectivity coherent; unrelated WHERE, ABS/CAST, projection and type changes no longer erase a valid JOIN proof.
  2. The proof covers predicate owners (JOIN ON, filters, block filters and vector-index prefilters). An unrelated warning in a projection retains its own owner and does not disable a selective JOIN. An invalid JOIN/filter operand still falls back to the conservative plan.
  3. The new errors.New sentinel was replaced by the repository-approved error constructor; make err-check passes, closing the exact-head SCA failure. The earlier DATE and HashJoin/LoopJoin findings from review 5326210418 remain covered by the existing contract and tests.

Verification and limits

  • Prior-head 9ccb74d984 Coverage repair: the new CN system-view startup fixture now advertises MORPC98, matching the production authoring gate. The prior 97 fixture could never pass admission and timed out in both variants. The focused test and full pkg/cnservice package pass under local -cover (65.9% package coverage). New-head CI is pending.
  • Four full owner package suites (pkg/sql/plan, pkg/sql/plan/function, pkg/frontend, pkg/sql/compile), make err-check, and git diff --check passed on prior head 9ccb74d984. Planner/frontend UTs cover final-binding proof, compile retry, projection vs predicate ownership, materialized literals, inactive CASE, aggregate wrappers, and vector-index prefilters.
  • A fresh Go 1.26.4 service built from prior head 9ccb74d984 passed the temporal BVT 370/370, with zero failed/ignored/abnormal statements. Real Connector/J 8.4 ServerPreparedStatement covers six valid JOIN shapes and valid→warning→NULL→valid reuse; the two-marker sequence returns 1/0/0/1 with warning counts 0/1/0/0.
  • On 20,000 rows per input, the reviewed failing two-marker plan produced 20,000 JOIN rows / ~2.08 MiB and a 6.72 ms local median. This source produces one JOIN row / ~32 KiB; the two-marker median is ~1.15 ms over 11 alternating Connector/J samples. With an invalid unrelated projected TIME marker, the old plan produced 20,000 JOIN rows / 2.08 MiB; this source produces one JOIN row / ~32 KiB while still publishing warning 1292. These are local plan/latency measurements, not throughput or RSS guarantees.
  • Independent QA challenged SQL and binary prepare, empty/no-match and guarded joins, warning recovery and direct-result metadata; final verdict: PASS, with no concrete blocker remaining. Historical release-4.2 restart/ABI evidence applies to unchanged paths. Full-repository CI and mixed-binary rolling deployment are not claimed; new-head GitHub CI must be judged separately.

Final integration repair (6ea989d2d2)

The last failing CI cases were four obsolete BVT expectations, not a reason to change the approved temporal domain: explicit out-of-range TIME CAST clamps to ±838:59:59 with warning 1292, while raw YEAR/MONTH/EXTRACT fields of accepted zero-date text return 0 independently of NO_ZERO_DATE. The four goldens are aligned, and a valid TIME(6) fractional-division control plus the clamp warning assertion preserve both precision and conversion coverage.

Independent high-effort review found one additional correctness defect: raw TIME DATE_ADD/SUB overloads were incorrectly marked volatile. This excluded deterministic statement-constant intervals from the JOIN diagnostic owner, yielding three overflow warnings for three matching pairs but none for two nonempty, nonmatching inputs. Removing those flags reuses the existing warning-isolated constant-folding/owner mechanism; row-dependent intervals remain row-scoped. A new BVT covers matched, no-match, empty, prepared reuse, decimal DATE_SUB, literal and inactive CASE paths.

Validation on the rebased source: the four previously failing BVT files passed 384/384 before the raw-interval correction (unaffected paths); after the correction, the new BVT passed 33/33 twice (including metadata comparison), and the existing temporal consistency BVT passed 370/370 twice on the same local service with teardown verified. Complete pkg/sql/plan/function and pkg/sql/plan suites, targeted executor tests, make err-check, and full-diff whitespace check passed. Rebased onto main 9c6fcb5b50; range-diff preserved all 50 original PR commits and added the two repair commits. Independent gpt-6-astra high review of the final revision reported no remaining concrete blocker. Fresh GitHub CI and a live mixed-binary rollout are not claimed.

Typed DATE follow-up (2026-09-27, 2405a72)

This update closes the two P2 findings in review 5330011503. Typed DATE/DATETIME-to-DATE CAST overload 1 now requires MORPC98 by executable identity, including serialized expressions without the optional syntax bit; the existing classifier protects placement, send, receive, and persisted authoring. Legacy CAST0 and assignment paths are unchanged. DATE overloads 0/2 and the exact typed CAST1 now have conservative nullable result metadata, propagated through the common binder into CTAS without a CTAS-specific exception or per-row executor change.

Adversarial validation covers released worker protocol versions 9/10 versus 98, absent syntax provenance, legacy CAST controls, public binding and serialization, prepared mode changes, and two-row CTAS through a derived projection. The new SQL BVT passed normal comparison 20/20 twice on the same isolated instance, with schema and stored NULL/valid rows checked and teardown verified. Full pkg/pb/plan, pkg/sql/plan/function, pkg/sql/plan, and pkg/sql/compile suites, scoped go vet, lint (0 issues), and diff checks passed. Independent GPT-6 medium final review found no actionable blocker.

Rebased onto main 9dfe5c1; range-diff preserved all 56 previous PR commits patch-equivalently and added one fix commit. Fresh GitHub CI and a live mixed-binary rollout are not claimed.

Final review repair and rebase (2026-09-27, 8dcb29f0a0)

This update closes the two findings in review 5330132584. Temporal arithmetic that can return NULL on overflow now has conservative nullable metadata through the common overload deduction, so CTAS/view schemas accept the result while an explicit NOT NULL destination still rejects it. A valid execution-local diagnostic proof now reaches physical JOIN selection for prepared guarded CASE/COALESCE, including the reversed orientation and retry path; invalid or active diagnostics stay conservative. The legacy stored overload identities and warning ownership are unchanged.

The PR is rebased onto main 5be6cd90b5. Compatibility is against released 4.2 protocols 9/10, not each unreleased main commit: integer arguments and temporal contracts share the integrated MORPC98 gate; main's writer-fair lock gate remains MORPC99. No MORPC100 epoch is introduced. Placement, send, receive, persisted-expression and derived-view admission agree on this boundary.

On the exact pushed source, full uncached CGo suites passed in pkg/sql/compile, pkg/sql/plan, pkg/sql/plan/function, pkg/frontend, pkg/cnservice, and pkg/lockservice; scoped JOIN race tests passed. A freshly built service on new isolated data passed all five affected SQL files 556/556 (arithmetic 12, guarded JOIN 35, typed DATE 20, raw interval 33, full temporal consistency 456). Real Connector/J ServerPreparedStatement on 2,000×2,000 rows reduced guarded CASE/COALESCE medians from 166/203 ms to 1.83/1.66 ms, near literal controls 1.19/1.13 ms. Independent read-only GPT-6 medium final review reported PASS/no confirmed blocker. Fresh CI and a live mixed-binary rollout are not claimed; CI is not awaited here.

@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 Sep 14, 2026
@jiangxinmeng1
jiangxinmeng1 marked this pull request as draft September 15, 2026 02:09
@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 Sep 15, 2026
@jiangxinmeng1
jiangxinmeng1 force-pushed the codex/date-compatibility-batch-20260914 branch from 458955d to cc59413 Compare September 15, 2026 02:32
This was referenced Sep 27, 2026

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/api-change kind/bug Something isn't working kind/enhancement kind/test-ci size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants