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

STL_WLM_QUERY

包含在由 WLM 处理的服务类中每次尝试执行查询的记录。

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

此表中的部分或全部数据也可以在 SYS 监控视图 SYS_QUERY_HISTORY 中找到。SYS 监控视图中的数据经过格式化处理,便于使用和理解。我们建议您使用 SYS 监控视图进行查询。

表列

列名称 数据类型 描述
userid integer 生成该条目的用户 ID。
xid integer 查询或子查询的事务 ID。
task integer 用于通过工作负荷管理器跟踪查询的 ID。可与多个查询 ID 关联。如果重新启动了某个查询,则会为该查询分配一个新的查询 ID 但不分配新的任务 ID。
query integer 查询 ID。如果重新启动了某个查询,则会为该查询分配一个新的查询 ID 但不分配新的任务 ID。
service_class integer 服务类的 ID。有关服务类 ID 的列表,请参阅 WLM 服务类 ID
slot_count 整数 根据为队列设置的并发级别,查询使用的 WLM 查询插槽的数量。默认值为 1。有关更多信息,请参阅 wlm_query_slot_count
service_class_start_time timestamp 将查询分配给服务类的时间。这个时间在 UTC 时区。
queue_start_time timestamp 查询进入服务类的队列的时间。这个时间在 UTC 时区。
queue_end_time timestamp 查询离开服务类的队列的时间。这个时间在 UTC 时区。
total_queue_time bigint 查询已在队列中消耗的总微秒数
exec_start_time timestamp 查询开始在服务类中执行的时间。这个时间在 UTC 时区。
exec_end_time timestamp 查询在服务类中完成执行的时间。这个时间在 UTC 时区。
total_exec_time bigint 查询进行执行所消耗的微秒数。
service_class_end_time timestamp 查询离开服务类的时间。这个时间在 UTC 时区。
final_state character(16) 保留供系统使用。
est_peak_mem bigint 保留供系统使用。
query_priority char(20) 查询的优先级。可能的值为 n/alowestlownormalhighhighest,其中 n/a 表示不支持查询优先级。
service_class_name character(64) 服务类名称。有关服务类的更多信息,请参阅 WLM 系统表和视图

示例查询

查看在队列中等待和执行的平均查询时间

以下查询显示 4 以上的服务类的当前配置。有关服务类 ID 的列表,请参阅 WLM 服务类 ID

以下查询返回针对每个服务类的每个查询在查询队列和执行过程中消耗的平均时间(单位为微秒)。

select service_class as svc_class, count(*), avg(datediff(microseconds, queue_start_time, queue_end_time)) as avg_queue_time, avg(datediff(microseconds, exec_start_time, exec_end_time )) as avg_exec_time from stl_wlm_query where service_class > 4 group by service_class order by service_class;

此查询返回以下示例输出:

svc_class | count | avg_queue_time | avg_exec_time -----------+-------+----------------+--------------- 5 | 20103 | 0 | 80415 5 | 3421 | 34015 | 234015 6 | 42 | 0 | 944266 7 | 196 | 6439 | 1364399 (4 rows)

查看在队列中等待和执行的最大查询时间

以下查询返回针对每个服务类的每个查询在任何查询队列和执行过程中消耗的总时间量(单位为微秒)。

select service_class as svc_class, count(*), max(datediff(microseconds, queue_start_time, queue_end_time)) as max_queue_time, max(datediff(microseconds, exec_start_time, exec_end_time )) as max_exec_time from stl_wlm_query where svc_class > 5 group by service_class order by service_class;
svc_class | count | max_queue_time | max_exec_time -----------+-------+----------------+--------------- 6 | 42 | 0 | 3775896 7 | 197 | 37947 | 16379473 (4 rows)