Apache Doris Profile&Explain详解
一、简述
Apache Doris中运行EXPLAIN + SQL就可以得到SQL对应的Query Plan,再结合Apche Doris的Profile可以了解Doris是如何处理SQL语句,用于分析查询语句或是结构的性能瓶颈,从而帮助选择更好的索引和写出更优化的查询语句。
二、Plan分析
2.1 sql准备
tpcds query96.sql为例
explain
-- explain graph 生成对应执行计划图表
select count(*)
from store_sales
,household_demographics
,time_dim
, store
where ss_sold_time_sk = time_dim.t_time_sk
and ss_hdemo_sk = household_demographics.hd_demo_sk
and ss_store_sk = s_store_sk
and time_dim.t_hour = 8
and time_dim.t_minute >= 30
and household_demographics.hd_dep_count = 5
and store.s_store_name = 'ese'
order by count(*) limit 100;
2.2 explain结果分析
Query Plan可以分为逻辑执行计划(Logical Query Plan)和物理执行计划(Physical Query Plan),当前讲述的Query Plan默认指逻辑执行计划;tpcds query96.sql对应的Query Plan展示如下。
-- graph
┌───────────────┐
│[8: ResultSink]│
│[Fragment: 4] │
│RESULT SINK │
└───────────────┘
│
│
┌─────────────┐
│[8: TOP-N] │
│[Fragment: 4]│
└─────────────┘
│
│
┌────────────────────────────────┐
│[13: AGGREGATE (merge finalize)]│
│[Fragment: 4] │
└────────────────────────────────┘
│
│
┌──────────────┐
│[12: EXCHANGE]│
│[Fragment: 4] │
└──────────────┘
│
│
┌────────────────────┐
│[12: DataStreamSink]│
│[Fragment: 0] │
│STREAM DATA SINK │
│ EXCHANGE ID: 12 │
│ UNPARTITIONED │
└────────────────────┘
│
│
┌─────────────────────────────────┐
│[7: AGGREGATE (update serialize)]│
│[Fragment: 0] │
└─────────────────────────────────┘
│
│
┌───────────────────────────────┐
│[6: HASH JOIN] │
│[Fragment: 0] │
│join op: INNER JOIN (BROADCAST)│
└───────────────────────────────┘
┌───────────┴─────────────────────────────────────┐
│ │
┌───────────────────────────────┐ ┌──────────────┐
│[4: HASH JOIN] │ │[11: EXCHANGE]│
│[Fragment: 0] │ │[Fragment: 0] │
│join op: INNER JOIN (BROADCAST)│ └──────────────┘
└───────────────────────────────┘ │
┌───────────────┴─────────────────────┐ │
│ │ ┌────────────────────┐
┌───────────────────────────────┐ ┌──────────────┐ │[11: DataStreamSink]│
│[2: HASH JOIN] │ │[10: EXCHANGE]│ │[Fragment: 3] │
│[Fragment: 0] │ │[Fragment: 0] │ │STREAM DATA SINK │
│join op: INNER JOIN (BROADCAST)│ └──────────────┘ │ EXCHANGE ID: 11 │
└───────────────────────────────┘ │ │ UNPARTITIONED │
┌─────────┴──────────┐ │ └────────────────────┘
│ │ ┌────────────────────┐ ┌┘
┌──────────────────┐ ┌─────────────┐ │[10: DataStreamSink]│ │
│[0: OlapScanNode] │ │[9: EXCHANGE]│ │[Fragment: 2] │ ┌─────────────────┐
│[Fragment: 0] │ │[Fragment: 0]│ │STREAM DATA SINK │ │[5: OlapScanNode]│
│TABLE: store_sales│ └─────────────┘ │ EXCHANGE ID: 10 │ │[Fragment: 3] │
└──────────────────┘ │ │ UNPARTITIONED │ │TABLE: store │
│ └────────────────────┘ └─────────────────┘
┌───────────────────┐ │
│[9: DataStreamSink]│ │
│[Fragment: 1]

ApacheDoris的EXPLAIN功能结合Profile可以帮助分析SQL查询的执行计划和性能。文章详细介绍了如何通过EXPLAIN展示的LogicalQueryPlan和PhysicalQueryPlan理解Doris如何处理SQL,以及通过Profile获取查询执行的详细信息,包括Join操作、Aggregation、Orderby和Top-N等,以识别性能瓶颈,辅助进行索引选择和查询优化。
3918

被折叠的 条评论
为什么被折叠?



