Skip to content

Support different EXPLAIN formats via SQL #15021

@alamb

Description

@alamb

Is your feature request related to a problem or challenge?

Suggested by @waynexia #14914 (comment)

Currently, DataFusion supports EXPLAIN and EXPLAIN ANALYZE as documented here: https://datafusion.apache.org/user-guide/sql/explain.html#id1

Both those commands produce a text based explain format:

> explain select * from values (1), (2);
+---------------+---------------------------------------------------+
| plan_type     | plan                                              |
+---------------+---------------------------------------------------+
| logical_plan  | Values: (Int64(1)), (Int64(2))                    |
| physical_plan | DataSourceExec: partitions=1, partition_sizes=[1] |
|               |                                                   |
+---------------+---------------------------------------------------+
2 row(s) fetched.
Elapsed 0.031 seconds.

DataFusion has at least three other text based ways to generate explain plans:

Also, @milenkovicm suggested on #14914 (comment) that getting an SVG version would also be useful

As of now it is not possible to see those formats via SQL (you need to use the API or set a config option)

Describe the solution you'd like

I would like to be able to access the different explain formats via SQL

Describe alternatives you've considered

@waynexia suggests (and I agree) on #14914 (comment)

That we follow the EXPLAIN [ANALYZE] FORMAT <format> grammar?:

EXPLAIN [ANALYZE] FORMAT <format>

So this would look something like

-- show explain plan in default text format
EXPLAIN  SELECT * from foo
-- show explain plan in tree format
EXPLAIN FORMAT tree SELECT * from foo
-- show explain plan in json format
EXPLAIN FORMAT json SELECT * from foo
-- ...

@waynexia suggests on #14914 (comment)

For the setting side, how about using the existing EXPLAIN [ANALYZE] FORMAT <format> grammar? sqlparser can parse and generate a AnalyzeFormat, which the planner can use. But our current implementation just drops this format field:

Statement::Explain {
verbose,
statement,
analyze,
format: _,
describe_alias: _,
..
} => {
self.explain_to_plan(verbose, analyze, DFStatement::Statement(statement))
}

We can also try to support GRAPHVIZ format in this way

However, It seems like AnalyzeFormat currently only supports Text, JSON, and GRAPHVIZ 🤔

https://docs.rs/sqlparser/latest/sqlparser/ast/enum.AnalyzeFormat.html

Additional context

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions