Skip to content

docs: define EXPLAIN FORMAT=JSON compatibility contract - #28415

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-28301-explain-json-design
Sep 11, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-28301-explain-json-design

Conversation

@VioletQwQ-0

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

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Refs #28301

What this PR does / why we need it:

Defines the executable compatibility contract for implementing MySQL EXPLAIN FORMAT=JSON.

The design fixes the accepted syntax and rejection boundary, the one-column/one-row protocol result, the v1 query_block mapping, and the complete reachable typed MatrixOne plan graph. It now specifies the field types, source mappings, omission and error rules for predicates, projections, limits, aliases, windows, frames, UPDATE row images, statistics, shared DAGs, and generic operators. It includes complete scan, join, CTE, window, UPDATE, and DELETE examples plus a prepared-protocol metadata contract and a fixed MySQL 8.0.45 comparison obligation.

Design revision: explain-format-json-2026-09-09-r2 (head 13324a7d12e98d8087e50608af40278b70721395, base 92a6bceba1ee156b87dc340479aa1cd44fe56a3d).

The implementation PR remains Draft until this design receives its independent review. QA is required for the feature; this documentation-only PR does not itself change executable behavior.

Implementation PR: #28435 (Draft, head 4f1341b37f387a4f97c6dda36468964bee52a1da, based on main 1cfec4c80134adc5640a3bbf1aef7aaa87a45282).

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

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

It is a fine thing to do, but why? who will use this? and why NOW?

Probably more useful is explain analyze, so if we do this thing at all, we should make sure explain format=json ANALYZE ... works. So the design saying will NOT support analyze and phyplan, makes the feature useless.

Again, I don't know why we should work on this. There are so many things that we should work on in stead of this ...

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Thanks for raising the scope question. The immediate users are machine-readable plan consumers—SQL clients, IDEs, and diagnostic/regression tooling—that should not parse text EXPLAIN. The reason to define this now is to establish one stable parser, renderer, frontend, and protocol boundary before implementation and QA, including MatrixOne-only shapes such as CTEs, windows, DML, and multi-step plans.

ANALYZE is intentionally separate from this static-plan v1. MySQL 8.0.45 documents EXPLAIN ANALYZE as TREE-only and rejects JSON with ANALYZE: https://dev.mysql.com/doc/refman/8.0/en/explain.html. Therefore v1 rejects EXPLAIN ANALYZE FORMAT=JSON before execution instead of inventing runtime metrics or side effects. A future ANALYZE design would need its own metrics, cancellation, and protocol contract. I added this rationale to the design document; implementation and QA remain pending.

Validation: docs-only; git diff --check passed and all seven JSON examples parse independently. The PR remains Ready.

@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 for the documentation-only design at head 9ec942a (base cd8e8d9). No concrete merge-blocking issue found.

Reviewed the full 365-line contract and current discussion: this is a prospective static-plan contract, explicitly not a claim that the implementation or QA has shipped. The machine-readable consumer rationale and separation from runtime ANALYZE are now explicit. The ANALYZE/JSON rejection agrees with the official MySQL 8.0 boundary: https://dev.mysql.com/doc/refman/8.0/en/explain.html . The limited query_block shape and MatrixOne extension do not promise Workbench/optimizer-field equivalence.

Evidence: independently parsed all seven JSON examples successfully; cross-checked typed Stats, OrderBySpec/WindowSpec/FrameClause and UpdateCtx source structures at this head, plus the actual VARCHAR -> VAR_STRING, setCharacter (0x21), and width-zero MaxUint32 metadata paths. Reviewed reachability/shared-DAG rules, field omission/non-finite handling, errors/no-write-pipeline requirement, and prepared metadata/validation obligations. Head/base were rechecked unchanged before submission. No executable code/tests are changed; no native UT/BVT, packet capture, or CI wait was performed.

Non-blocking implementation follow-ups: keep the SQL-associated examples clearly distinguished from actual optimizer output (the join fixture includes predicates absent from its displayed SQL; the CTE fixture's source_steps=[1] points at its own step root). Before freezing client-facing v1 output, enumerate statistics subkeys/units and compatibility evolution rules so implementations do not independently choose names. These are refinements to illustrative/extension details, not evidence of an executable regression in this docs-only PR.

This approval does not approve implementation PR #28435 or waive its exact-head renderer, protocol, permission/no-side-effect, scale, and fixed-MySQL QA obligations.

@mergify mergify Bot added the queued label Sep 11, 2026
@mergify

mergify Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-11 03:43 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-11 03:43 UTC · at b922526ecb40f70e02f59e68b83ba3996a7325e5 · squash

This pull request spent 13 seconds in the queue, including 2 seconds running CI.

Required conditions to merge

@mergify
mergify Bot merged commit b922526 into matrixorigin:main Sep 11, 2026
21 of 22 checks passed
@mergify mergify Bot removed the queued label Sep 11, 2026
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#28415)

Defines the executable compatibility contract for implementing MySQL `EXPLAIN FORMAT=JSON`.

The design fixes the accepted syntax and rejection boundary, the one-column/one-row protocol result, the v1 `query_block` mapping, and the complete reachable typed MatrixOne plan graph. It now specifies the field types, source mappings, omission and error rules for predicates, projections, limits, aliases, windows, frames, UPDATE row images, statistics, shared DAGs, and generic operators. It includes complete scan, join, CTE, window, UPDATE, and DELETE examples plus a prepared-protocol metadata contract and a fixed MySQL 8.0.45 comparison obligation.

Design revision: `explain-format-json-2026-09-09-r2` (head `13324a7d12e98d8087e50608af40278b70721395`, base `92a6bceba1ee156b87dc340479aa1cd44fe56a3d`).

The implementation PR remains Draft until this design receives its independent review. QA is required for the feature; this documentation-only PR does not itself change executable behavior.

Implementation PR: matrixorigin#28435 (Draft, head `4f1341b37f387a4f97c6dda36468964bee52a1da`, based on `main` `1cfec4c80134adc5640a3bbf1aef7aaa87a45282`).

Approved by: @XuPeng-SH
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#28415)

Defines the executable compatibility contract for implementing MySQL `EXPLAIN FORMAT=JSON`.

The design fixes the accepted syntax and rejection boundary, the one-column/one-row protocol result, the v1 `query_block` mapping, and the complete reachable typed MatrixOne plan graph. It now specifies the field types, source mappings, omission and error rules for predicates, projections, limits, aliases, windows, frames, UPDATE row images, statistics, shared DAGs, and generic operators. It includes complete scan, join, CTE, window, UPDATE, and DELETE examples plus a prepared-protocol metadata contract and a fixed MySQL 8.0.45 comparison obligation.

Design revision: `explain-format-json-2026-09-09-r2` (head `13324a7d12e98d8087e50608af40278b70721395`, base `92a6bceba1ee156b87dc340479aa1cd44fe56a3d`).

The implementation PR remains Draft until this design receives its independent review. QA is required for the feature; this documentation-only PR does not itself change executable behavior.

Implementation PR: matrixorigin#28435 (Draft, head `4f1341b37f387a4f97c6dda36468964bee52a1da`, based on `main` `1cfec4c80134adc5640a3bbf1aef7aaa87a45282`).

Approved by: @XuPeng-SH
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#28415)

Defines the executable compatibility contract for implementing MySQL `EXPLAIN FORMAT=JSON`.

The design fixes the accepted syntax and rejection boundary, the one-column/one-row protocol result, the v1 `query_block` mapping, and the complete reachable typed MatrixOne plan graph. It now specifies the field types, source mappings, omission and error rules for predicates, projections, limits, aliases, windows, frames, UPDATE row images, statistics, shared DAGs, and generic operators. It includes complete scan, join, CTE, window, UPDATE, and DELETE examples plus a prepared-protocol metadata contract and a fixed MySQL 8.0.45 comparison obligation.

Design revision: `explain-format-json-2026-09-09-r2` (head `13324a7d12e98d8087e50608af40278b70721395`, base `92a6bceba1ee156b87dc340479aa1cd44fe56a3d`).

The implementation PR remains Draft until this design receives its independent review. QA is required for the feature; this documentation-only PR does not itself change executable behavior.

Implementation PR: matrixorigin#28435 (Draft, head `4f1341b37f387a4f97c6dda36468964bee52a1da`, based on `main` `1cfec4c80134adc5640a3bbf1aef7aaa87a45282`).

Approved by: @XuPeng-SH
XuPeng-SH pushed a commit that referenced this pull request Oct 13, 2026
## What type of PR is this?
- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [x] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:
issue #28301 (QA-gated reference; no automatic closure).

## What this PR does / why we need it:
Implement SQL `EXPLAIN FORMAT=JSON` with a stable one-column JSON
result, typed planner/execution semantics and no DML side effects.
Preserve existing text EXPLAIN and reject unsupported combinations
explicitly.

### Current exact-head conflict delivery — 2026-10-12

Published `1512185965e33dda4b98fc7388792b19c0d696dd`, tree
`8973ddf86ce25ad9c32b5718376dd30430454bc5`, normal parents
`b94d81e9e832f65f56a0baeaf20e66665afd57e1` and actual main
`f802ab6a6fd66fed0f094d1772a6f93049004e8a`. Generated-parser conflict
repaired by reproducible whole-file generation; EXPLAIN renderer/design
and both canonical SQL/result pairs unchanged.

Actual Go 1.27.1 Darwin/arm64 CPU/CGo validation: owning parser 198
roots/732 named, owning EXPLAIN 124/324; focused parser/planner/frontend
and prepared NULL/type-reuse tests, `-vet=all`, incremental lint and
feature diff-check PASS. Real production LOG/TN/CN SQLIntegration
fixture with unchanged Java normal comparator: EXPLAIN JSON 68/68 and
JSON_TABLE 73/73 each twice, all 282 comparisons PASS; independent
catalog/stage cleanup and graceful fixture/test termination PASS. No
fresh standalone binary or packet capture is claimed.

Fresh current head is Ready/MERGEABLE; new-head CI, reviewer clearance
and deployed/client QA remain pending. aptend's terminal-CI acceptance
is not waived by local results. The following sections retain historical
source-bound evidence, not the current CI status. QA Decision remains
yes; issue #28301 remains a reference, not automatic closure wording.

### Prior merge repair — 2026-10-10 (historical)

Current published head: `e539f8768da2de613d5fb61bd7a049e9f296e910`, a
normal merge with parents `c030817533989bbd9ae1b8a95610ae441538330a` and
actual main `590601d62aa3c2fb6165d389ee710ed483c98da7`. The committed
tree is `400c502df6f89dda22da75b89228f2b827e4d794`. Synchronization
addressed an actual generated-parser conflict, not `BEHIND` alone.

The complete parser was regenerated from the combined EXPLAIN FORMAT /
JSON_TABLE grammar, preserving both families and upstream UTF-8
statement recording. Repeated generation was byte-identical with zero
shift/reduce or reduce/reduce conflicts. Existing EXPLAIN renderer
behavior is unchanged in this resolution.

Validation of this exact committed tree, independently audited:
- Linux/amd64 Go 1.27.1, genuine CGo-enabled production build: PASS.
- Owning parser suite: 193 root tests / 717 named tests; focused
frontend consumers: 9 root tests / 55 named tests, including prepared
EXPLAIN metadata/authorization and UTF-8 recording: PASS.
- Incremental parser/frontend lint and final diff check: PASS.
- Canonical normal-comparison BVT: `optimizer/explain_format_json.sql`
(68 assertions) and `function/table_func_json_table.sql` (73
assertions), each twice on the same private instance; all 282
comparisons: PASS.
- Mixed JSON_TABLE + EXPLAIN FORMAT=JSON query, each teardown, and
graceful service shutdown (exit 0, no forced kill): PASS.

The tested binary SHA256 is
`d76512e512e06444d2f214642ea9d1cc5c3d9f74250265ef51bbc29b87c84466`.
[Published exact-tree delivery
evidence](#28435 (comment))
records its binding and limits.

Current-head [CI run
38065542272](https://github.com/matrixorigin/matrixone/actions/runs/38065542272),
attempt 2, remains in progress as of 2026-10-10 18:13 UTC. Ubuntu UT,
arm64 SCA, Compose/PROXY and Compose/PESSIMISTIC completed successfully;
coverage unit tests are still executing. Attempt 1's coverage producer
failed during source checkout before tests. The one authorized
failed-jobs rerun recovered setup and reached actual coverage tests; no
terminal coverage PASS or whole-run green result is claimed.

aptend's current-head terminal-CI delivery gate remains open. aptend is
already in the review-request list; this metadata correction neither
duplicates the request nor resolves a finding or clears
CHANGES_REQUESTED. Historical MySQL wire evidence retains its original
SHA and only unchanged protocol scope. Actual deployed/client
integration QA remains NOT_RUN; no fresh packet capture, blanket
acceptance or issue closure is claimed.

QA required: **yes** — user-visible SQL/protocol behavior and
deployment/client acceptance remain relevant. This PR keeps an issue
reference rather than automatic closure wording.

### Prior merge validation — 2026-10-09 (historical)

The preceding `c030817533989bbd9ae1b8a95610ae441538330a` revision
incorporated `8f48d6fac04bf612be65ed1b44477ef9b32cb88f` into
`dc7c85efba7b97d3064209ad18d2b3171b0178fe`, with 35 focused roots / 79
named tests. Its original evidence is historical, not a substitute for
the current-tree build/BVT results above. The obsolete response helper
stayed removed and both malformed-vector and ordinary-cache-generation
regressions were retained.

### Historical semantic repair validation (original revisions)
- Head: `6fbe0b51f97f57831ce02f1c57ffca648fc86886`; CR increment from
`32a7ffd8d14547a0249648bde024384aad004a72`.
- Validation base remains `86b2602ff20606c2582decd26e63a1d56ed6ee25`; no
rebase for `BEHIND` alone. Accepted design: #28415, merge
`b922526ecb40f70e02f59e68b83ba3996a7325e5`.
- Three separate repair commits preserve recursive UNION DISTINCT/ALL,
FILL mode/optimized target/value roles, and complete typed serialized
scalar/vector bytes. Malformed complete vectors fail before successful
result publication; text EXPLAIN retains its existing contract.
- Exact-old-head counterexamples fail on the reported omissions. Final
explain owning-package run: 123 top-level tests PASS; frontend
metadata/prepared/reprepare/error-publication checks: 4/4 PASS;
changed-package lint and diff-check PASS.
- Canonical EXPLAIN JSON BVT: 68/68 PASS twice on one dedicated
single-CN candidate instance, retaining scan/vector
bounds/FirstRoundLimit/SAMPLE/DISTINCT controls. Cleanup verified
between runs and at end; instance stopped and ports released.
- Independent real SQL direct/prepared JSON-content checks: 26/26 PASS,
one row/one column. Runtime string provenance can retain scalar lists;
the public planner regression independently verifies folded
`IsSerialized` vector identity and exact values.
- Historical fixed MySQL 8.0.45/MO wire-client matrix 8/8 PASS and
direct/SQL-prepared DML row-image controls 6/6 PASS are reused within
their original scope: metadata/prepare/reprepare/protocol production
paths are unchanged. This is not a new packet-capture claim.
- Historical decoded protocol artifact and limitations:
#28435 (comment)
- Current repair commits, candidate binary/source binding, test
evidence, initial-attempt corrections and reviewer-specific disposition:
#28435 (comment)

### Historical acceptance notes (original revisions)
- QA required: **yes**. Deployment/actual-client integration QA is
**NOT_RUN** in this increment; no issue closure is requested.
- Current-head CI and reviewer re-review remain independent gates.
Re-review has been requested from aptend, XuPeng-SH, iamlinjunhong and
aunjgr; author-side thread resolution is not reviewer approval.
- No claim of MySQL byte-identical JSON/metadata, a measured
`Com_stmt_reprepare` counter, or binary-DML coverage.


### SCA follow-up — 2026-10-08

Published head: `dc7c85efba7b97d3064209ad18d2b3171b0178fe` (parent
`4cc703a51bfbf94aebf443551a4af87068e68fae`). Exact-parent SCA run
37719517356/job 113123764007 reported four `prealloc` diagnostics in
`sql_json_semantics_test.go`. This follow-up only preallocates the four
test-local string slices; all inputs, loops, assertions, fixtures and
production code remain unchanged.

Validation on Darwin/arm64: configured golangci-lint 2.14.0 / Go 1.27.0
owning `pkg/sql/plan/explain` scan PASS (0 issues); controlled
`mo-cgo-test -json -count=1 -timeout=180s ./pkg/sql/plan/explain` PASS
(324 named tests/subtests and package PASS, zero failures); gofmt and
`git diff --check` PASS. Existing canonical EXPLAIN SQL/result BVT
remains unchanged. No additional BVT run is claimed for this test-only
initialization change; earlier semantic evidence retains its original
SHA. New-head required CI is pending and must independently satisfy
aptend's terminal-CI acceptance gate before re-review. No blanket
review, deployment QA, or issue closure is claimed.

---------

Co-authored-by: 大雾重重 <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@VioletQwQ-0
VioletQwQ-0 deleted the codex/issue-28301-explain-json-design branch December 1, 2026 03:47

This branch was previously deployed

1 inactive deployment
ci — 9ec942a8 Deployed Sep 11, 2026 by VioletQwQ-0 via Matrixone Utils CI / pr-size-label #52792
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/documentation Improvements or additions to documentation size/XS Denotes a PR that changes [1, 9] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants