STL_EXPLAIN - Amazon Redshift
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

STL_EXPLAIN

显示已提交供执行的查询的 EXPLAIN 计划。

STL_EXPLAIN 对所有用户可见。超级用户可以查看所有行;普通用户只能查看其自己的数据。有关更多信息,请参阅系统表和视图中的数据可见性

注意

STL_EXPLAIN 仅包含在主集群上运行的查询。它不包含在并发扩展集群上运行的查询。要访问在主集群和并发扩展集群上运行的查询,我们建议您使用 SYS 监控视图 SYS_QUERY_DETAIL。SYS 监控视图中的数据经过格式化处理,便于使用和理解。

表列

列名称 数据类型 描述
userid integer 生成该条目的用户 ID。
query integer 查询 ID。查询列可用于连接其他系统表和视图。
nodeid integer 计划节点标识符,在执行查询时一个节点将映射到一个或多个步骤。
parentid integer 父节点的计划节点标识符。父节点具有一些数量的子节点。例如,合并联接是针对联接表的扫描的父级。
plannode character(400) EXPLAIN 输出中的节点文本。表示在计算节点上执行的计划节点在 EXPLAIN 输出中使用 XN 作为前缀。
info character(400) 计划节点的限定词和筛选条件信息。例如,联接条件和 WHERE 子句限制包括在此列中。

示例查询

考虑聚合联接查询的以下 EXPLAIN 输出:

explain select avg(datediff(day, listtime, saletime)) as avgwait from sales, listing where sales.listid = listing.listid; QUERY PLAN ------------------------------------------------------------------------------ XN Aggregate (cost=6350.30..6350.31 rows=1 width=16) -> XN Hash Join DS_DIST_NONE (cost=47.08..6340.89 rows=3766 width=16) Hash Cond: ("outer".listid = "inner".listid) -> XN Seq Scan on listing (cost=0.00..1924.97 rows=192497 width=12) -> XN Hash (cost=37.66..37.66 rows=3766 width=12) -> XN Seq Scan on sales (cost=0.00..37.66 rows=3766 width=12) (6 rows)

如果您运行此查询且其查询 ID 为 10,则您可以使用 STL_EXPLAIN 表来查看 EXPLAIN 命令返回的同类信息:

select query,nodeid,parentid,substring(plannode from 1 for 30), substring(info from 1 for 20) from stl_explain where query=10 order by 1,2; query| nodeid |parentid| substring | substring -----+--------+--------+--------------------------------+------------------- 10 | 1 | 0 |XN Aggregate (cost=6717.61..6 | 10 | 2 | 1 | -> XN Merge Join DS_DIST_NO | Merge Cond:("outer" 10 | 3 | 2 | -> XN Seq Scan on lis | 10 | 4 | 2 | -> XN Seq Scan on sal | (4 rows)

请考虑以下查询:

select event.eventid, sum(pricepaid) from event, sales where event.eventid=sales.eventid group by event.eventid order by 2 desc; eventid | sum --------+---------- 289 | 51846.00 7895 | 51049.00 1602 | 50301.00 851 | 49956.00 7315 | 49823.00 ...

如果此查询的 ID 为 15,则以下系统视图查询返回已完成的计划节点。在这种情况下,将反转节点的顺序以显示执行的实际顺序:

select query,nodeid,parentid,substring(plannode from 1 for 56) from stl_explain where query=15 order by 1, 2 desc; query|nodeid|parentid| substring -----+------+--------+-------------------------------------------------------- 15 | 8 | 7 | -> XN Seq Scan on eve 15 | 7 | 5 | -> XN Hash(cost=87.98..87.9 15 | 6 | 5 | -> XN Seq Scan on sales(cos 15 | 5 | 4 | -> XN Hash Join DS_DIST_OUTER(cos 15 | 4 | 3 | -> XN HashAggregate(cost=862286577.07.. 15 | 3 | 2 | -> XN Sort(cost=1000862287175.47..10008622871 15 | 2 | 1 | -> XN Network(cost=1000862287175.47..1000862287197. 15 | 1 | 0 |XN Merge(cost=1000862287175.47..1000862287197.46 rows=87 (8 rows)

以下查询检索包含一个窗口函数的任何查询计划的查询 ID:

select query, trim(plannode) from stl_explain where plannode like '%Window%'; query| btrim -----+------------------------------------------------------------------------ 26 | -> XN Window(cost=1000985348268.57..1000985351256.98 rows=170 width=33) 27 | -> XN Window(cost=1000985348268.57..1000985351256.98 rows=170 width=33) (2 rows)