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

时间:2017-01-04 21:56:24

标签: amazon-redshift data-warehouse

我正在使用redshift对一些查询进行基准测试,以便我可以对我对表所做的更改说出一些智能,例如添加编码和运行真空。我可以使用LIKE子句查询stl_query表来查找我感兴趣的查询,因此我有查询ID,但像stv_query_summary这样的表/视图太精细了,我不是确定如何生成我需要的摘要!

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

2 个答案:

答案 0 :(得分:2)

要添加到Alex的答案,我想评论stl_query表有一个不便之处,如果查询在运行时之前在队列中,那么队列时间将包含在运行时中,因此运行时将不是非常好的查询性能指标。

要了解查询的实际运行时,请在stl_wlm_query上查看total_exec_time。

select total_exec_time
from stl_wlm_query
where query='query_id'

答案 1 :(得分:1)

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