我收集了来自RDS的慢速查询日志,并将它们放到一个文件中。尝试通过pt-query-digest
,following instructions here运行它,但是它将整个文件作为单个查询读取。
命令:
pt-query-digest --group-by fingerprint --order-by Query_time:sum collider-slow-query.log > slow-query-analyze.txt
输出,表明它仅分析了一个查询:
# Overall: 1 total, 1 unique, 0 QPS, 0x concurrency ______________________
这只是一个简短的代码段,其中包含来自正在分析的文件的2个查询,以演示有很多查询:
2019-05-03T20:44:21.828Z # Time: 2019-05-03T20:44:21.828954Z
# User@Host: username[username] @ [ipaddress] Id: 19
# Query_time: 17.443164 Lock_time: 0.000145 Rows_sent: 5 Rows_examined: 121380
SET timestamp=1556916261;
SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND wp_posts.ID NOT IN (752921) AND (
wp_term_relationships.term_taxonomy_id IN (40)
) AND wp_posts.post_type = 'post' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 5;
2019-05-03T20:44:53.597Z # Time: 2019-05-03T20:44:53.597137Z
# User@Host: username[username] @ [ipaddress] Id: 77
# Query_time: 35.757909 Lock_time: 0.000054 Rows_sent: 2 Rows_examined: 199008
SET timestamp=1556916293;
SELECT post_id, meta_value FROM wp_postmeta
WHERE meta_key = '_wp_attached_file'
AND meta_value IN ( 'family-guy-vestigial-peter-slice.jpg','2015/08/bobs-burgers-image.jpg','2015/08/bobs-burgers-image.jpg' );
为什么它不读取所有查询?我的串联有问题吗?
答案 0 :(得分:0)
我也有同样的问题。事实证明,SQL中还存储了一些额外的时间戳(通过此变量https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_log_timestamps)。
这使pt-query-digest无法看到单个查询。应该通过关闭timestamp变量或删除timestamp来轻松解决该问题:
2019-10-28T11:17:18.412 # Time: 2019-10-28T11:17:18.412214
# User@Host: foo[foo] @ [192.168.8.175] Id: 467836
# Query_time: 5.839596 Lock_time: 0.000029 Rows_sent: 1 Rows_examined: 0
use foo;
SET timestamp=1572261432;
SELECT COUNT(*) AS `count` FROM `foo`.`invoices` AS `Invoice` WHERE 1 = 1;
通过删除第一个时间戳(2019-10-28T11:17:18.412
部分),它可以再次工作。