说明
支持内核:Presto、SparkSQL。
支持表类型:原生表、外部表。
用途:展示执行 sql 的逻辑或物理计划。
语法
Presto
EXPLAIN [ ( option [, ...] ) ] statement-- where option can be one of:-- FORMAT { TEXT | GRAPHVIZ | JSON }-- TYPE { LOGICAL | DISTRIBUTED | VALIDATE | IO }
SparkSQL
EXPLAIN [ EXTENDED | CODEGEN | COST | FORMATTED ] statementEXPLAIN ANALYZEEXPLAIN ANALYZE [VERBOSE] statement
示例
-- prestoEXPLAIN (TYPE VALIDATE) SELECT regionkey, count(*) FROM nation GROUP BY 1;EXPLAIN (TYPE IO, FORMAT JSON) INSERT INTO test_nation SELECT * FROM nation WHERE regionkey = 2;-- EXPLAIN ANALYZEEXPLAIN ANALYZE SELECT count(*), clerk FROM orders WHERE orderdate > date '1995-01-01' GROUP BY clerk;EXPLAIN ANALYZE VERBOSE SELECT count(clerk) OVER() FROM orders WHERE orderdate > date '1995-01-01';