Skip to main content

EXPLAIN

使用 EXPLAIN 命令显示语句的执行计划。

句法

EXPLAIN [ ( option [ , ... ] ) ] statement;

参数

参数描述
statement在 RisingWave 中可执行的语句。
EXPLAIN 选项请参阅下表。

EXPLAIN 选项

选项描述
VERBOSE [ TRUE | FALSE ]显示有关执行计划的其他信息,例如状态表的表目录和每个运算符的 schema。
TRACE [ TRUE | FALSE ]对每个优化阶段而不仅仅是最终计划进行追踪。
TYPE [ PHYSICAL | LOGICAL | DISTSQL ]显示特定阶段的执行计划。
  • PHYSICAL — 显示批处理计划或流计划。
  • LOGICAL — 显示优化后的逻辑计划。
  • DISTSQL — 显示批处理或流的分布式查询计划。
note

布尔参数 [ TRUE | FALSE ] 指定是否启用或禁用指定的选项。使用 TRUE 启用选项,使用 FALSE 禁用选项。如果未指定参数,则默认为 TRUE

示例

下面的语句可显示 SELECT 语句的执行计划。

EXPLAIN SELECT
o_orderpriority,
count(*) AS order_count
FROM
orders
WHERE
o_orderdate >= date '1997-07-01'
and o_orderdate < date '1997-07-01' + interval '3' month
and exists (
SELECT
*
FROM
lineitem
WHERE
l_orderkey = o_orderkey
and l_commitdate < l_receiptdate
)
GROUP BY
o_orderpriority
ORDER BY
o_orderpriority;

执行计划如下:

 BatchExchange { order: [orders.o_orderpriority ASC], dist: Single }
BatchSort { order: [orders.o_orderpriority ASC] }
BatchHashAgg { group_key: [orders.o_orderpriority], aggs: [count] }
BatchExchange { order: [], dist: HashShard(orders.o_orderpriority) }
BatchHashJoin { type: LeftSemi, predicate: orders.o_orderkey = lineitem.l_orderkey }
BatchExchange { order: [], dist: HashShard(orders.o_orderkey) }
BatchProject { exprs: [orders.o_orderkey, orders.o_orderpriority] }
BatchFilter { predicate: (orders.o_orderdate >= '1997-07-01':Varchar::Date) AND (orders.o_orderdate < ('1997-07-01':Varchar::Date + '3 mons 00:00:00':Interval)) }
BatchScan { table: orders, columns: [o_orderkey, o_orderpriority, o_orderdate] }
BatchExchange { order: [], dist: HashShard(lineitem.l_orderkey) }
BatchProject { exprs: [lineitem.l_orderkey] }
BatchFilter { predicate: (lineitem.l_commitdate < lineitem.l_receiptdate) }
BatchScan { table: lineitem, columns: [l_orderkey, l_commitdate, l_receiptdate] }
(13 rows)

下面的语句可显示 CREATE MATERIALIZED VIEW 语句的执行计划。

EXPLAIN CREATE MATERIALIZED VIEW nexmark_q3 AS
SELECT P.name, P.city, P.state, A.id
FROM auction AS A INNER JOIN person AS P on A.seller = P.id
WHERE A.category = 10 and (P.state = 'OR' OR P.state = 'ID' OR P.state = 'CA');

上述语句的执行计划如下:

                      QUERY PLAN
-----------------------------------------------------------
StreamMaterialize { columns: [name, city, state, id, _row_id(hidden), _row_id#1(hidden)], pk_columns: [_row_id, _row_id#1] }
StreamExchange { dist: HashShard([4, 5]) }
StreamProject { exprs: [$4, $5, $6, $0, $2, $7] }
StreamHashJoin { type: Inner, predicate: $1 = $3 }
StreamProject { exprs: [$0, $1, $3] }
StreamExchange { dist: HashShard([1]) }
StreamFilter { predicate: ($2 = 10:Int32) }
StreamTableScan { table: auction, columns: [id, seller, category, _row_id], pk_indices: [3] }
StreamExchange { dist: HashShard([0]) }
StreamFilter { predicate: ((($3 = 'OR':Varchar) OR ($3 = 'ID':Varchar)) OR ($3 = 'CA':Varchar)) }
StreamTableScan { table: person, columns: [id, name, city, state, _row_id], pk_indices: [4] }