matrixorigin / matrixorigin/matrixone
[Compatibility]: MySQL EXPLAIN FORMAT=JSON is unavailable
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 311
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 768
Description
### Is there an existing issue for the same bug?
- [x] I have checked the existing issues.
### Branch Name
main
### Commit ID
74668fc075c965c462b30f10ae24a1c19c289cfd
### Other Environment Information
```Markdown
- MatrixOne was built from the commit above and started locally with etc/launch/launch.toml.
- MySQL comparison version: 8.0.45.
- Every statement was repeated three times with the same result.
```
### Actual Behavior
MatrixOne does not provide the MySQL `EXPLAIN FORMAT=JSON` interface.
The MySQL syntax is rejected by the MatrixOne parser:
```sql
EXPLAIN FORMAT=JSON SELECT * FROM target_t WHERE id=1;
```
MatrixOne's parenthesized syntax recognizes `JSON`, but execution rejects it:
```sql
EXPLAIN (FORMAT JSON) SELECT * FROM target_t WHERE id=1;
```
```text
not supported: Unsupport explain format 'json'
```
The same rejection occurs for a table scan, join, CTE, window query, UPDATE,
and DELETE. Ordinary text `EXPLAIN` works for the same statements.
The explain formatter contains explicit JSON NYI branches across query and
node formatting, so this is not limited to one plan node.
### Expected Behavior
MatrixOne should accept MySQL's `EXPLAIN FORMAT=JSON` syntax and return a valid
JSON document describing the plan. MySQL 8.0.45 returns JSON plans for every
statement below.
### Steps to Reproduce
```sql
CREATE DATABASE codex_explain_json_0907;
USE codex_explain_json_0907;
CREATE TABLE target_t(id INT PRIMARY KEY, v INT);
CREATE TABLE source_t(id INT PRIMARY KEY, v INT);
INSERT INTO target_t VALUES(1,10),(2,20),(3,30);
INSERT INTO source_t VALUES(1,101),(2,202),(4,404);
-- MySQL-compatible syntax is rejected by the MatrixOne parser.
EXPLAIN FORMAT=JSON SELECT * FROM target_t WHERE id=1;
-- MatrixOne syntax parses JSON but the formatter rejects it.
EXPLAIN (FORMAT JSON) SELECT * FROM target_t WHERE id=1;
EXPLAIN (FORMAT JSON)
SELECT * FROM target_t t JOIN source_t s ON s.id=t.id;
EXPLAIN (FORMAT JSON)
WITH c AS (SELECT * FROM source_t) SELECT * FROM c WHERE id=1;
EXPLAIN (FORMAT JSON)
SELECT ROW_NUMBER() OVER(ORDER BY id) FROM target_t;
EXPLAIN (FORMAT JSON)
UPDATE target_t SET v=v+1 WHERE id=1;
EXPLAIN (FORMAT JSON)
DELETE FROM target_t WHERE id=1;
-- Control: text format works.
EXPLAIN SELECT * FROM target_t WHERE id=1;
EXPLAIN (FORMAT TEXT) SELECT * FROM target_t WHERE id=1;
```
### Additional information
The JSON formatter paths return explicit NYI errors in
`pkg/sql/plan/explain/explain_node.go` and
`pkg/sql/plan/explain/explain_query.go`.
Contributor guide
Assessment
This issue has not been assessed yet.