Presto-[12]-Syntax-EXPLAIN

来源:互联网 发布:原油api数据公布网站 编辑:程序博客网 时间:2024/06/06 02:23

原文

https://prestodb.io/docs/current/sql/explain.html

学习EXPLAIN,可用于执行cost评估和合法性检测

Synopsis

EXPLAIN [ ( option [, ...] ) ] statementwhere option can be one of:    FORMAT { TEXT | GRAPHVIZ }    TYPE { LOGICAL | DISTRIBUTED | VALIDATE }

Description

展示statement的逻辑、分布式执行计划或者statement的有效性。用TYPE DISTRIBUTED option展示分片组织的plan,每个plan的分片fragment被一个或多个nodes执行。

Fragments的切分形式同时反映着数据在presto nodes间的exchange关系。Fragment的类型标识fragment如何在Presto nodes 中执行,

也标识着数据如何在fragments中分布。

SINGLE
在单节点上执行的Fragment
HASH
将输入数据以 轮询方式进行分散distributed,使得Fragment在固定数量的nodes上执行。
ROUND_ROBIN
将输入数据用hash函数进行分散distributed
BROADCAST
将输入数据以broadcasted广播到所有节点上去 ,使得Fragment在固定数量的nodes上执行。
SOURCE
Fragment在可获得splits的节点上执行

Examples

Logical plan:

presto:tiny> EXPLAIN SELECT regionkey, count(*) FROM nation GROUP BY 1;                                                Query Plan---------------------------------------------------------------------------------------------------------- - Output[regionkey, _col1] => [regionkey:bigint, count:bigint]         _col1 := count     - RemoteExchange[GATHER] => regionkey:bigint, count:bigint         - Aggregate(FINAL)[regionkey] => [regionkey:bigint, count:bigint]                count := "count"("count_8")             - LocalExchange[HASH][$hashvalue] ("regionkey") => regionkey:bigint, count_8:bigint, $hashvalue:bigint                 - RemoteExchange[REPARTITION][$hashvalue_9] => regionkey:bigint, count_8:bigint, $hashvalue_9:bigint                     - Project[] => [regionkey:bigint, count_8:bigint, $hashvalue_10:bigint]                             $hashvalue_10 := "combine_hash"(BIGINT '0', COALESCE("$operator$hash_code"("regionkey"), 0))                         - Aggregate(PARTIAL)[regionkey] => [regionkey:bigint, count_8:bigint]                                 count_8 := "count"(*)                             - TableScan[tpch:tpch:nation:sf0.1, originalConstraint = true] => [regionkey:bigint]                                     regionkey := tpch:regionkey

Distributed plan:

presto:tiny> EXPLAIN (TYPE DISTRIBUTED) SELECT regionkey, count(*) FROM nation GROUP BY 1;                                          Query Plan---------------------------------------------------------------------------------------------- Fragment 0 [SINGLE]     Output layout: [regionkey, count]     Output partitioning: SINGLE []     - Output[regionkey, _col1] => [regionkey:bigint, count:bigint]             _col1 := count         - RemoteSource[1] => [regionkey:bigint, count:bigint] Fragment 1 [HASH]     Output layout: [regionkey, count]     Output partitioning: SINGLE []     - Aggregate(FINAL)[regionkey] => [regionkey:bigint, count:bigint]             count := "count"("count_8")         - LocalExchange[HASH][$hashvalue] ("regionkey") => regionkey:bigint, count_8:bigint, $hashvalue:bigint             - RemoteSource[2] => [regionkey:bigint, count_8:bigint, $hashvalue_9:bigint] Fragment 2 [SOURCE]     Output layout: [regionkey, count_8, $hashvalue_10]     Output partitioning: HASH [regionkey][$hashvalue_10]     - Project[] => [regionkey:bigint, count_8:bigint, $hashvalue_10:bigint]             $hashvalue_10 := "combine_hash"(BIGINT '0', COALESCE("$operator$hash_code"("regionkey"), 0))         - Aggregate(PARTIAL)[regionkey] => [regionkey:bigint, count_8:bigint]                 count_8 := "count"(*)             - TableScan[tpch:tpch:nation:sf0.1, originalConstraint = true] => [regionkey:bigint]                     regionkey := tpch:regionkey

Validate:

presto:tiny> EXPLAIN (TYPE VALIDATE) SELECT regionkey, count(*) FROM nation GROUP BY 1; Valid------- true

原创粉丝点击