如何通过查询获取 Redshift 中查询的总运行时间?

问题描述 投票:0回答:3

我正在对 redshift 中的一些查询进行基准测试,以便我可以对我对表所做的更改做出一些明智的判断,例如添加编码和运行真空。我可以使用 LIKE 子句查询

stl_query
表来查找我感兴趣的查询,因此我有查询 id,但是像
stv_query_summary
这样的表/视图太细粒度了,我不是确定如何生成我需要的摘要!

GUI仪表板显示了我感兴趣的指标,但格式很难存储以供以后分析/比较(换句话说,我想避免截图)。有没有一种好的方法可以使用 sql selects 重建该视图?

amazon-redshift data-warehouse
3个回答
4
投票

为了补充Alex的答案,我想评论一下stl_query表有一个不便之处,如果查询在运行时之前位于队列中,那么队列时间将包含在运行时中,因此运行时不会很好查询的性能指标。

要了解查询的实际运行时间,请检查 stl_wlm_query 的total_exec_time。

select total_exec_time
from stl_wlm_query
where query='query_id'

3
投票

https://github.com/awslabs/amazon-redshift-utils有一些有用的工具/脚本

这里是其中一个被删除的脚本,为您提供以毫秒为单位的查询运行时间。使用过滤器、排序等来显示您正在寻找的结果:

select userid, label, stl_query.query, trim(database) as database, trim(querytxt) as qrytext, starttime, endtime, datediff(milliseconds, starttime,endtime)::numeric(12,2) as run_milliseconds, aborted, decode(alrt.event,'Very selective query filter','Filter','Scanned a large number of deleted rows','Deleted','Nested Loop Join in the query plan','Nested Loop','Distributed a large number of rows across the network','Distributed','Broadcasted a large number of rows across the network','Broadcast','Missing query planner statistics','Stats',alrt.event) as event from stl_query left outer join ( select query, trim(split_part(event,':',1)) as event from STL_ALERT_EVENT_LOG group by query, trim(split_part(event,':',1)) ) as alrt on alrt.query = stl_query.query where userid <> 1 -- and (querytxt like 'SELECT%' or querytxt like 'select%' ) -- and database = '' order by starttime desc limit 100
    

0
投票
SELECT user_id, query_id, transaction_id, session_id, status, trim(database_name) AS database_name, start_time, end_time, result_cache_hit, elapsed_time, queue_time, execution_time, planning_time, trim(query_text) as query_text, query_label FROM sys_query_history WHERE query_type = 'SELECT' AND query_label = 'Monday' AND result_cache_hit = 'false' ORDER BY start_time DESC limit 10
    
© www.soinside.com 2019 - 2024. All rights reserved.