// Explain in SQL
scala> sql("EXPLAIN EXTENDED show tables").show(truncate = false)
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|plan |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|== Parsed Logical Plan ==
ShowTablesCommand
== Analyzed Logical Plan ==
tableName: string, isTemporary: boolean
ShowTablesCommand
== Optimized Logical Plan ==
ShowTablesCommand
== Physical Plan ==
ExecutedCommand
+- ShowTablesCommand|
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
ExplainCommand Logical Command
ExplainCommand
is a logical command that allows users to see how a structured query will be executed. It takes in a LogicalPlan
and creates a QueryExecution that is used to output a single-column DataFrame
with the following:
-
codegen explain, i.e. WholeStageCodegen subtrees if
codegen
flag is enabled. -
extended explain, i.e. the parsed, analyzed, optimized logical plans with the physical plan if
extended
flag is enabled. -
simple explain, i.e. the physical plan only when no
codegen
andextended
flags are enabled.
ExplainCommand
is used for explain operator and EXPLAIN
SQL statement (accepting EXTENDED
and CODEGEN
options).
The following EXPLAIN variants in SQL queries are not supported:
-
EXPLAIN FORMATTED
-
EXPLAIN LOGICAL
scala> sql("EXPLAIN LOGICAL show tables")
org.apache.spark.sql.catalyst.parser.ParseException:
Operation not allowed: EXPLAIN LOGICAL(line 1, pos 0)
== SQL ==
EXPLAIN LOGICAL show tables
^^^
...