Skip to content

fix(sql): align approximate numeric text notation with MySQL - #30316

Merged
XuPeng-SH merged 25 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/1ffa5784428cb25224175acaae3709b19809c81226d8ade686e4d13b57b6ef8c
Oct 28, 2026
Merged

XuPeng-SH merged 25 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/1ffa5784428cb25224175acaae3709b19809c81226d8ade686e4d13b57b6ef8c

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 15, 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:

Related to #30227; leave open for reporter verification.

What this PR does / why we need it:

Align FLOAT/DOUBLE scalar and JSON text notation with MySQL while preserving binary JSON numeric values/types and existing fulltext token spelling. Shared formatting remains bounded and stateless.

Repair execution-owned historical catalog expressions whose implicit DOUBLE-to-string casts were bound to width 32. Reconstruct the complete SQL origin before widening; preserve explicit CHAR widths, assignment limits, folded DEFAULT values, shared catalog trees and idempotence. Legacy DUMP admission reconstructs the same historical binder era.

Historical trees can omit implicit collation coercibility that current binding records. A private historical candidate can omit only missing implicit markers for supported revision-zero byte collations. Present/invalid, explicit, native and conflicting provenance remains exact; DUMP retains exact syntax provenance and the generic comparator is unchanged. Cancellation now propagates through the existing repair owner. The redundant single-use refinement dispatcher is removed.

Tests retain independent predecessor fixtures, actual expression execution, truncation/NULL/assignment controls, DUMP tamper rejection, source immutability, cancellation and native-collation boundaries. Ineligible explicit/direct controls assert whole-table immutability rather than requiring unrelated metadata upgrades.

Scope remains common exponent/JSON notation and safe implicit bounds. MySQL's expression-specific scalar buffer-width rounding is outside this change.

The current repair also reconstructs complete creation-session witnesses for historical folded DEFAULT expressions. Time-zone/locale probes use a private process, preserve stored constants and explicit widths, share one cancellation/work budget, and publish only after complete old/current tree proofs. The actual-conflict rebase preserves current DUMP JSON, temporal and DDL-column-scope eras; historical JSON text folding is a separate proof-only candidate, while current JSON admission and lazy consumer identities remain intact.

Catalog repair preserves the complete original CREATE column scope alongside catalog/ALTER scope, including NOT NULL and primary-key declarations. Session search first rejects impossible precision/type witnesses. For opaque folded boundaries, it pre-folds independent descendants and probes only session-dependent constant islands across supported zones/locales. Equivalent probes share evaluation while retaining every original binding candidate; a hint must still pass the complete SQL-origin and current-binding proofs. The shared work budget is unchanged. DUMP uses the same hints for float DEFAULT candidates while retaining exact supplied-payload verification and its configured limit.

COPY ALTER normalizes only its private live-source replay copy through the same catalog migration owners as planning. The normalization runs inside each replica preparation, including the fresh source used by main's second generation after concurrent writes. This preserves frozen DEFAULT values when old engine metadata and the repaired replacement use different implicit widths, while retaining source identity/version, freshness, retirement and foreign-key checks.

Compose historical float and integer/DECIMAL binding eras before normalizing execution-owned catalogs. Preserve folded DEFAULT constants, catalog ownership and exact origin checks. Metadata-only ALTER can persist the repaired expression; DUMP reconstructs that state from independently SQL-bound candidates under the original work budget, without normalizing supplied payloads.

Successful creation-session witnesses are shared across DEFAULTs within one table verification. Retain at most eight timezone/locale pairs; every expression still binds its own SQL, precision, era and scope and must pass complete origin/current-tree or supplied-payload checks. This avoids repeating expensive discovery for a second valid DEFAULT under the unchanged table-wide budget. Hints never cross table operations. DUMP retains its sensitivity analysis and unavailable-binding fallback.

Distinct creation sessions share immutable folded-island results within one table verification, keyed by the exact residual source, effective folding context, timezone identity and locale. Equality-safe negative fingerprints avoid repeated decoding and comparison; matching fingerprints still require full island comparison and each expression's own authoritative proof. Each probe uses its own stored and already-folded reading-session string payload lengths only as search-order information. No precision is inherited from another DEFAULT. A priority pass is bounded to a quarter of the remaining work and is skipped when every candidate ties; all candidates remain available to the unchanged fair search and full-binding fallback. Shape agreement cannot accept a candidate and shape disagreement cannot exclude one. The work cap remains 1M visits; optional memo retention stops at 32 MiB of charged bytes or 65,536 source/result records. Errors and partial folds are never cached, and no results survive the table operation.

Validation

  • New at 3c49eba907fcdd17d6e1f2d10e5533c15e3e9546, rebased onto official c4946bb74d43f0f777977507a5a7d0105e628bf2: all 22 PR patches remain (21 equivalent; one context adjustment). JSON_UNQUOTE retains main's native-string fast path and immediate result ownership, with the context-scoped historical numeric formatter on its nonstring fallback. Main's subject reuse, prefix validation and MORPC134 remain intact; no new wire capability.
  • New controlled CGo checks with -short -tags=matrixone_test -p=2 -count=1 -timeout=300s pass for ./pkg/container/bytejson ./pkg/internal/bytejsonvalidate ./pkg/sql/plan/function ./pkg/sql/plan with default vet (0.642s / 0.929s / 8.225s / 66.241s). Focused JSON_UNQUOTE tests cover text/native values, NULL/masks, invalid/binary domains and output survival after inline/area input overwrite/free. Historical JSON DEFAULT fixtures, full catalog/DUMP origin/tamper checks and the 0–30 precision matrix pass. Incremental golangci-lint over the eight changed PR package directories reports 0 issues.
  • New -run '^TestORLikeSubjectReuse' consumer checks pass all 22 named roots in colexec, filter and table_scan (0.989s / 0.983s / 0.916s). Existing typed bounds, NULL/error, CASE, admission, invocation/reset and rollback controls cover composition with the additive function metadata API.
  • Reused prior b866788fa99616b928c6ce76b65865f6398482bd evidence for unchanged migration/replay sources: five owner packages passed, eight barrier-based COPY ALTER refresh cells passed, and same-disk SELECT/default INSERT/UPDATE/COPY ALTER/DUMP/LIKE/LOAD/restored DML preserved frozen values. The historical writer uses legacy width/format owners on current dependencies, not a full historical-release binary. Historical DEFAULT replay and concurrent refresh were separately exercised, not combined in a new live run. No service upgrade was rerun for this string-only fast path.
  • Reused dispatch CI run 40540836873 for completed coverage, shared build and both enabled BVT groups. UT and SCA were still running at intake and are not claimed passed. Fresh rebase CI is pending; no old run was rerun.

Independent conflict design and final overall review: gpt-6-astra / medium, PASS, zero unresolved material findings. No whole-workload performance claim is made.

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

@mergify mergify Bot added the kind/bug Something isn't working label Oct 15, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Oct 15, 2026
@XuPeng-SH

XuPeng-SH commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 5c251b03282789dd04563ff57b25f9de229a37ee

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 5c251b03282789dd04563ff57b25f9de229a37ee

Assessment: request_changes

Reviewed all 28 changed files and affected callers. Centralizing display formatting while preserving fulltext token spelling is reasonable, but the planner’s unchanged string-width bound causes reproducible numeric truncation.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

  • P2 pkg/sql/plan/function/func_cast.go:10738: SELECT CONCAT(CAST('-1.2345678901234567e-15' AS DOUBLE));
    Impact: The new formatter emits 34 bytes, but formattedStringByteBound still assigns DOUBLE a 32-byte bound in string_result_domain.go:123. CONCAT consequently inserts a VARCHAR(32) cast that silently removes significant digits. Update the shared planner bound to accommodate the new maximum and add SQL regression coverage for long fractional representations.
    Evidence: The SQL planner/executor probe returns '-0.00000000000000123456789012345'; an explicit CHAR(64) cast returns '-0.0000000000000012345678901234568'. Three boundary cases fail and two nearby controls pass. All five pass when func_cast.go is restored from the base through an overlay. Retained evidence: consumer-tests.jsonl with receipt 1792092789851193424-2.json; width-base-control.jsonl with receipt 1792092815190166890-2.json.

Validation:

  • Reconciled commands, source fingerprints, exit receipts and retained logs in /home/xupeng/.local/state/mo-bot/jobs/82496bc199f00a56cac3859b/attempt-1/validation-audit.json. Source remains unchanged.

  • Isolation preflight passed. Recovered native prerequisites through Makefile cgo after verifying 192 inputs and 62 artifacts; the initial missing-header failure occurred before bytejson tests executed.

  • Utility, bytejson, aggexec and function package suites passed. Focused Parquet and remote-expression tests passed. Additional probes verified 21,896 finite DOUBLE values, FLOAT precision, binary JSON round-trips, unchanged fulltext tokens and nonfinite rejection.

  • Three-sample microbenchmarks measured five-value JSON serialization increasing from 165 to 247 ns/op for ordinary numbers and 189 to 253 ns/op for exponent cases, with unchanged allocations. Scalar exponent formatting reduced allocations from two to one.

  • The frozen evidence reports successful exact-head Ubuntu UT, Linux/arm64 SCA and both BVT groups; individual CI case logs were unavailable.

Limitations:

  • The reproduction exercises SQL parsing, planning and expression execution, not a live frontend connection.

  • No live MySQL comparison or local full-service BVT rerun. Author execution artifacts and the full linked-issue body were not supplied.

  • Base comparisons use exact base formatting-source overlays on current dependencies. Microbenchmarks do not establish end-to-end SQL performance.

XuPeng-SH and others added 16 commits October 28, 2026 01:11
Reconstruct only affected subtrees so unrelated persisted FORMAT and internal
SET FIND_IN_SET bindings remain intact. Rebuild affected FORMAT arguments with
the catalog VARCHAR(max) declaration and scope internal binding to SQL-origin
verified trees. Charge affected scans and FORMAT normalization to the existing
candidate budget.

Preserve official main's DUMP binding eras and session witnesses after rebase,
with an orthogonal historical float mode and owned default-session scratch.
Pin the historical CHECK name in its independent compatibility fixture test.

Add seven independent predecessor-source fixtures plus insert/update BVT
compositions. Validation: full plan package, focused formatter/JSON consumers,
real seven-table catalog upgrade, and two 37/37 BVT rounds with teardown checks.

Addresses review 5566548101 for matrixorigin#30227.
Reconstruct legacy IN/NOT IN coercions through their binding owner,
including nullable comparisons expanded from membership expressions.
Keep historical equality, overload identity, whole-tree equivalence,
explicit cast limits, copy-on-write ownership and resource guards.

Traverse persisted expression owners lazily so unaffected tables avoid
allocating a candidate slice during resolution.

Add nine independent historical fixtures, execution and allocation
regressions, and public SQL coverage for IN/NOT IN/NULL/explicit casts.

Validation: full planner package, vet and lint pass; nine historical
catalog tables pass INSERT/UPDATE after same-disk restart using exact
predecessor CAST/width overlays on current dependencies. BVT passes
42/42 twice with teardown verified. One warm-up plus three measured
rounds reduces clone+migration from 22,976 B/10 allocations to
1,600 B/2 allocations, matching clone-only allocations.

Addresses review 5598679079 on PR matrixorigin#30316. Related to matrixorigin#30227.
Reconstruct predecessor scalar and recursive JSON constant formatting only
inside isolated catalog proof evaluators. Keep typed folded constants
intact while widening live conversions, and independently verify the
complete current SQL tree with authenticated frozen-constant boundaries.

DUMP now considers historical folding even without surviving casts, and
admits repaired mixed trees without relaxing ordinary payload equality.
Select the extra eras from resolved formatting dependencies to preserve
unrelated temporal budgets. Retain explicit/assignment casts, overloads,
source ownership, cancellation, warning isolation and resource limits.

Add 22 independent historical definitions and regression tests for mixed
and fully folded defaults, JSON text, prior-width/current-format catalogs,
provenance rejection, budget failures and evaluator isolation.

Validation: full planner/function/ByteJson suites with vet; focused final
compatibility and temporal budget tests; lint reports zero issues. A
service with predecessor scalar/JSON/width source overlays on current
dependencies created 21 tables. Same-disk upgrade, metadata DUMP/LOAD and
subsequent INSERT/UPDATE pass, with teardown verified. Two normal BVT
rounds pass 47/47 each with zero ignored cases. This is source-overlay
compatibility evidence, not a complete historical-release binary test.

Addresses review 5601322358 on PR matrixorigin#30316. Related to matrixorigin#30227.
@XuPeng-SH

XuPeng-SH commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 3c49eba907fcdd17d6e1f2d10e5533c15e3e9546

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: 3c49eba907fcdd17d6e1f2d10e5533c15e3e9546

Assessment: approve

Reviewed the complete 63-file delta, linked issue and all 44 discussion entries. Formatting and binder-owned catalog repair preserve explicit widths, frozen defaults, catalog ownership and exact DUMP validation. Prior findings, including the precision-8 CREATE/ALTER failure, are resolved by current source and execution evidence. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Evidence and discussion-assessment.json are retained under /home/xupeng/.local/state/mo-bot/jobs/b43b20301e26854c53fdfdbb/attempt-1. Source remained unchanged.

  • Isolation preflight passed. Native prerequisites were independently qualified against 200 input hashes, seven output hashes and the repository build owner's receipt.

  • Current-head execution passed 57 focused test roots and six COPY ALTER controls across five packages. Logs: focused-tests.jsonl and alter-controls.jsonl; receipts: 1793126552641314183-3.json and 1793126798352884227-4.json.

  • Retained suites, historical fixtures and benchmarks were qualified by source, command, exit and artifact hashes. The original precision-8 fixture passed at the current head in approximately 104 ms.

  • Final evidence audit passed: validation-audit.json, final-audit.log and receipt 1793126828377405005-4.json. Frozen CI reports successful enabled UT, SCA, build, coverage and BVT checks.

Limitations:

  • No independently qualified full-service historical-release upgrade or new live MySQL comparison. Historical producer fixtures use predecessor formatting owners on newer dependencies. CI case logs were unavailable; upgrade lanes were skipped.

  • Retained microbenchmarks show five-double JSON serialization increasing from approximately 200–205 to 261–279 ns, with unchanged allocations. They do not establish whole-workload performance; historical catalog reconstruction retains bounded per-resolution costs.

  • Expression-specific MySQL scalar-buffer rounding remains outside the accepted scope. This assessment does not close the linked issue's reporter verification.

@mergify

mergify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

❌ Left the queue · Matrixone CI execution / UT Test on Ubuntu/x86 fails with this pull request

1 h 41 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Tue 27 Oct, 22:05 · rule main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in place
  • 🚫 Left the queue 23:46 · 79fe508

The failure is in this pull request. It failed tested alone on top of main.

Reason

The merge conditions cannot be satisfied due to failing checks

  • CI Required

Failing checks:

To get back in the queue

  • Push a fix: the pull request is queued again once its queue conditions match.
  • If the failure is a flake, comment @mergifyio queue to queue it again as it is.
Merge conditions: 2 of 3 met

This pull request

Condition Required by
✅ #review-threads-unresolved = 0 GitHub branch protection
✅ github-review-approved GitHub branch protection

The batch, tested in place

Condition Required by
❌ any of: check-neutral = CI Required, check-skipped = CI Required, check-success = CI Required GitHub branch protection

Requeued — the merge queue status continues in this comment ↓.

Times in UTC · dashboard · how the merge queue works

@mergify

mergify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue

3 h 16 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Wed 28 Oct, 01:36 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 04:52 · 7df26e0

Reason

Pull request #30316 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Merge conditions: 2 of 3 met

This pull request

Condition Required by
✅ #review-threads-unresolved = 0 GitHub branch protection
✅ github-review-approved GitHub branch protection

The batch, tested in place

Condition Required by
❌ any of: check-neutral = CI Required, check-skipped = CI Required, check-success = CI Required GitHub branch protection

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

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

dequeued kind/bug Something isn't working kind/enhancement kind/refactor Code refactor 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