Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: support explain plan in JSON format #39261

Open
2 tasks
fzzf678 opened this issue Nov 21, 2022 · 9 comments · May be fixed by #47401
Open
2 tasks

planner: support explain plan in JSON format #39261

fzzf678 opened this issue Nov 21, 2022 · 9 comments · May be fixed by #47401
Labels
sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@fzzf678
Copy link
Contributor

fzzf678 commented Nov 21, 2022

Enhancement

JSON is a language-independent format for data exchange and easy to decode. With this format, optimizer plan can be easily decoded, as well as easy integration with 3rd party tools. It was supported in MySQL since 5.6. In order to improve scalability and compatibility, we need a JSON format output of explain result.

Notice: this json format is not same with MySQL‘s, we use format = tidb_json distinguish

TODO

@fzzf678 fzzf678 added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner labels Nov 21, 2022
@adamf-db
Copy link

+1 to this enhancement.

@dveeden
Copy link
Contributor

dveeden commented Sep 28, 2023

+1 to this enhancement.

GitHub uses the reactions to the issue description when filtering and sorting. Please add a 👍 to the issue description to vote for this issue.

@dveeden
Copy link
Contributor

dveeden commented Sep 28, 2023

I would suggest to change the title to "planner: support MySQL compatible JSON explain format".

The benefits and disadvantages for FORMAT=JSON:

  • Compatible with MySQL and IDE's etc
  • Might not show the same level of detail as this format wasn't made for TiDB and there might not be a good or logical place for some info.

The benefits and disadvantages of FORMAT=TIDB_JSON

  • Full details on TiDB specific things
  • IDE's might need changes to use this format and the output of this format.

Note that MySQL also has FORMAT=TREE, which we also don't support in TiDB. Maybe that should be another issue?

@dveeden
Copy link
Contributor

dveeden commented Sep 29, 2023

image

This shows the executeInfo in the TIDB_JSON being a string instead of an object.

It is now like this:

"executeInfo": "time:127.2µs, loops:2, RU:0.000000, build_hash_table:{total:40.7µs, fetch:32.7µs, build:8.09µs}, probe:{concurrency:5, total:25.2µs, max:20.6µs, probe:16.4µs, fetch:8.81µs}",

It probably should be like this:

"executeInfo": {"time":"127.2µs", "loops":2, "RU":0.000000, "build_hash_table":{"total":"40.7µs", "fetch":"32.7µs", "build":"8.09µs"}, "probe":{"concurrency":5, "total":"25.2µs", "max":"20.6µs", "probe":"16.4µs", "fetch":"8.81µs"}",

(not sure if the values should be strings here with the unit (µs) or if they unit should be part of the key (e.g. "fetch_ms")

@dveeden
Copy link
Contributor

dveeden commented Sep 29, 2023

Do you want a MySQL compatible JSON explain output or the TiDB explain output, but with executeInfo, etc encoded as JSON object instead of a string?

@adamf-db
Copy link

adamf-db commented Oct 1, 2023

For now, the TIDB explain output as JSON, including the full executeInfo encoded as JSON instead of a string.

@adamf-db
Copy link

adamf-db commented Oct 1, 2023

Also, I agree with encoding the unit either in the key name or as another k:v at the same depth, eg { "time": { "count": 12.684, "unit": "milliseconds"} but I think that's for another issue.

@dveeden
Copy link
Contributor

dveeden commented Oct 5, 2023

In #47401 I make some changes that do some of this. Note that this is just a early draft, not something that's ready and/or complete.

Example:
image

@adamf-db
Copy link

adamf-db commented Oct 5, 2023

@dveeden that looks good to me - JSON all the way down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants