Skip to content

fix(json): preserve MySQL binary subtype fidelity - #28092

Merged
XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/28057-bytejson-fidelity
Sep 6, 2026
Merged

XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/28057-bytejson-fidelity

Conversation

@VioletQwQ-0

@VioletQwQ-0 VioletQwQ-0 commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • Bug fix
  • Feature
  • Engineering

Which issue(s) this PR fixes:

issue #28057
issue #28058

What this PR does / why we need it:

Preserves MySQL binary subtypes and raw payload bytes in ByteJson without adding a persistent type code. BINARY, VARBINARY, and BLOB use legacy-readable TpCodeBlob values containing base64:typeN payloads. New readers accept legacy bare Base64, the prior BIT sentinel, and the new tags.

This update adds the rolling-upgrade admission contract before tagged values are produced: NewMySQLOpaque requires the minimum admitted MORPC version (MORPCVersion50, following the target's v46-v49 prefix) and rejects older writers before constructing tagged payloads. The stacked SQL constructor PR must pass that explicit admission value.

Tagged payload recognition now parses only the bounded typeN: header. Valid tagged terminal operations validate or decode the payload at most once; TYPE does not materialize the payload. Malformed tags fail closed as raw BLOB bytes across type inspection, comparison, payload length, and canonicalization.

QA required: yes — this is the storage/representation foundation for a compatibility stack and issues remain open until exact-version QA completes.

Production terminal covered by automation: ByteJson root/nested marshal, vector storage, merge, comparison/hash, payload length, legacy-reader compatibility, rolling-upgrade admission, malformed-tag fallback, and existing CAST constant folding.

Remaining QA

Mixed-version disk reads and the full constructor SQL surface remain covered by the stacked PRs and tester handoff. The local CGo-transitive pkg/sql/plan/function check must be rerun when the native cgo/libmo.dylib prerequisite is available; the direct bytejson/vector/defines/keycodec validation is green.

Validation:

  • Focused exact-layer go test for ./pkg/container/bytejson: PASS, including admission rejection/acceptance, legacy/sentinel compatibility, malformed fallback, and 1 MiB allocation checks.
  • go test for ./pkg/container/vector, ./pkg/defines, and ./pkg/common/hashmap/keycodec: PASS.
  • ByteJson build and go vet: PASS.
  • Semantic preflight manifest and final self-review: PASS.
  • git diff --check: PASS.
  • CGo-transitive mo-cgo-test for ./pkg/sql/plan/function: BLOCKED — the isolated environment lacks cgo/libmo.dylib and the native third-party prerequisite; no test assertion failed.
  • BVT: N/A — this layer exposes the representation/storage primitive; production constructor SQL changes begin in fix(json): unify constructor value conversion #28093.
  • Equivalent regression: ByteJson root/array/object/merge/marshal/vector compatibility tests, protocol admission matrix, malformed-tag fallback, and hot-path allocation tests.
  • Fresh CI: pending on pushed head; the prior exact-head Ubuntu UT failure was a runner/TLS setup failure before test execution.

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Sep 3, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Sep 3, 2026
@VioletQwQ-0
VioletQwQ-0 force-pushed the codex/28057-bytejson-fidelity branch from 1dea66f to 238ed53 Compare September 4, 2026 03:53
@VioletQwQ-0
VioletQwQ-0 force-pushed the codex/28057-bytejson-fidelity branch from 238ed53 to 2c10567 Compare September 4, 2026 05:04
@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Rebased/merged current main into the PR branch to resolve the merge conflict.

Current exact head: af834f7ba69e30b53374e1c47455a0e3bdc33a47. The bytejson/defines focused tests pass, and git diff --check is clean. The PR remains Ready; fresh CI and reviewer re-review are pending.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

The first post-conflict UT result is an external runner failure, not a source/test assertion. Job 101455253637 failed before tests: setup-java lost its TLS connection, and the runner also reported that the Docker API socket was unavailable; no MatrixOne test case executed. No rerun was triggered.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Addressed XuPeng-SH's two blocking findings on exact head 49e05f7745f8890c3c1630900b2d8b7042e2168d.

  • Mixed-version admission: after rebasing onto target main at c1293102fd18908b59c4b049140aad67a50e0b16, the existing MORPC capabilities v46-v49 remain occupied and MySQLOpaqueProtocolVersion is MORPCVersion50. NewMySQLOpaque rejects MORPCVersion49 before constructing a tagged value; the v50 acceptance path is covered by TestMySQLOpaqueRequiresRollingUpgradeAdmission. The stacked SQL constructor must pass its actual admitted version.
  • Decode cost and fail-closed behavior: tagged recognition parses only the bounded typeN: header; valid terminal paths avoid repeated payload materialization, TYPE performs validation without allocating the decoded payload, and malformed tags remain raw BLOB bytes. The 1 MiB tagged comparison regression and benchmark pass with 0 B/op and 0 allocs/op.

Focused ByteJson/vector/defines/keycodec tests, build, vet, diff-check, semantic preflight, and final self-review pass. The CGo-transitive pkg/sql/plan/function check remains blocked by the missing isolated-environment cgo/libmo.dylib prerequisite; no assertion failed. The previous Ubuntu UT setup failure was before test execution due runner/TLS setup.

No inline review threads were present to resolve. Please re-review this exact head.

@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 re-review of exact head 49e05f7745f8890c3c1630900b2d8b7042e2168d.

The previous mixed-version admission and normal tagged-payload hot-path findings are substantially closed: construction now requires v50 admission, same-subtype compare decodes once without allocation, and TYPE validates without materializing the payload.

[P1] Restore comparison/canonical-key equivalence for malformed-tag fallback

The new forceRaw branch in compareBinaryJSONValues compares both operands through binaryJSONFallbackBytes. For a valid tagged peer, that helper returns the complete stored base64:typeN:... text, while canonicalization decodes that peer to its payload. This creates values that compare unequal but have identical resident/spill keys.

Concrete counterexample at the ByteJson boundary:

  • A = TpCodeBlob("base64:type16:not-base64"). The tag payload is malformed, so the promised fail-closed interpretation is a raw BLOB whose bytes are the full string.
  • B = NewMySQLOpaque(v50, 252, []byte("base64:type16:not-base64")). This is a valid tagged BLOB whose decoded payload is exactly As fallback bytes.
  • AppendCanonicalBinary(A) and AppendCanonicalBinary(B) both produce marker || type252 || "base64:type16:not-base64".
  • CompareBinaryJSON(A, B) resolves A to forceRaw, then compares As raw bytes with Bs complete base64:type252:... storage text and returns non-zero.

That violates the key invariant used by GROUP BY, DISTINCT, hash join/routing, and spill: scalar equality and canonical equality must define the same equivalence relation. It also means the PR-body claim that malformed tags fail closed consistently across comparison and canonicalization is not yet true.

Please represent a malformed value after resolution as an ordinary raw BLOB payload (rather than forcing both peers into storage-text comparison), so a valid encoded peer is still compared through its decoded payload. Add bidirectional tests asserting sign(compare) == key equality for malformed type16/type252 tags against valid tagged BLOBs carrying the fallback bytes, plus malformed legacy bare-Base64 and nested/hash-key coverage. Keep the fixed valid-payload fast path allocation-free.

Delivery note: v50 is also allocated by other open PRs; after this fix, rebase on the then-current main and retain a unique latest protocol allocation.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Addressed the current-head malformed-tag equivalence finding in d0ee0af17e340958413408ac3cd076f7d1233a01:

  • Malformed tagged values now resolve to an ordinary raw-BLOB payload view instead of forcing comparison against the complete stored tag text.
  • Valid tagged peers therefore compare decoded payload bytes against the same fallback bytes in either operand order.
  • Added bidirectional type16/type252 tagged regressions, malformed legacy Base64 coverage, and nested array/keycodec coverage asserting comparison equality matches canonical-key equality.

Validation: full pkg/container/bytejson and pkg/common/hashmap/keycodec packages pass with -race -count=2; focused go vet passes; git diff --check and schema-v6 semantic preflight PASS.

Please re-review this exact Ready head.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Follow-up for the current head 0b9f3ae25e131d1b8be767db98bd3a775a4ddeb1:

  • Rebased the complete fix onto the then-current main (a6ee7171327e3999e33748d4c872994178fabcdf). The upstream sequence already allocates MORPC v50/v51, so this change now reserves the unique v52 slot for MySQL binary JSON subtype tags and updates the admission tests accordingly.
  • Kept the malformed-tag repair: invalid type16/type252 and legacy base64 tags resolve to ordinary raw BLOB payload bytes before comparison, so both operand orders and nested canonical keys agree with valid tagged BLOB values.
  • Validation: GOWORK=off go test -mod=readonly -race -count=100 for each focused regression; full ./pkg/container/bytejson and ./pkg/common/hashmap/keycodec race packages; go vet; git diff --check; semantic preflight PASS semantic=PASS.

Please review the current head, especially the v52 allocation and malformed-tag comparison/canonical-key equivalence.

@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 against current head e348620.

The two previously blocking concerns are closed:

  • mixed-version behavior is gated behind a unique MORPC protocol version while legacy readers retain the historical type-code path;
  • malformed tag handling now preserves comparison and canonical-key equivalence.

Counterexample review covered malformed and valid tag pairs, raw BLOB fallback, mixed-version admission, empty payloads, large payloads, canonical-key consistency, and comparison/TYPE allocation behavior. I found no remaining correctness, compatibility, unhappy-path, or material performance blocker.

The head changed during review because main was merged. I verified that the old-base/old-head and new-base/new-head diffs have the same stable patch-id bacde14285c9221095956c773e34eb3084241402. The only direct old-head/new-head differences are main-side test updates, so the reviewed PR semantics are unchanged.

Local execution is blocked by the known macOS CGo prerequisite absence: cgo/libmo.dylib is not available in the isolated worktree. This is an environment prerequisite failure rather than a test assertion failure.

@mergify

mergify Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-06 15:42 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-06 15:55 UTC · at e3486208aca06ab4d6cf363ec1e1bd72629cb811

This pull request spent 13 minutes 28 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]

Reason

Pull request #28092 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.

Failing checks:

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.

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

  • Requeue this pull request

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants