简体   繁体   English

如何使用PHP Profiler跟踪Mysql慢查询日志文件条目

[英]How to Trace Mysql Slow-query-log-file Entries Using PHP Profiler

I just started using PHP profiler to find files in php script which caused slow mysql queries. 我刚开始使用PHP分析器在php脚本中查找文件,导致mysql查询速度慢。 Some suggested that I use xdebug to track it with the timestamp from the slow log-file entry compared to the files in php profiler that was executed at the same timestamp. 有人建议我使用xdebug来跟踪慢速日志文件条目中的时间戳,而不是在同一时间戳执行的php profiler中的文件。

I have read the xdebug documentation but can't find an explanation of this problem. 我已阅读xdebug文档但无法找到此问题的解释。

Can anyone give me enlightenment? 任何人都可以给我启蒙吗?

I'm using php 7.0, Debian 9. 我正在使用php 7.0,Debian 9。

My slow-query-log-file entries: 我的慢查询日志文件条目:

# Thread_id: 222244  Schema: user  QC_hit: No
# Query_time: 51.019708  Lock_time: 0.000119  Rows_sent: 1  Rows_examined: 13295012
# Rows_affected: 0
SET timestamp=1559388099;
SELECT (COUNT(*)) AS `count` 
FROM statistics Statistics WHERE (id >= 1 AND ad_type <> 3);

Edit: 编辑:

It's not about counting rows in a SELECT statement, but it's about how to track application files that cause slow requests to occur. 它不是关于SELECT语句中的行计数,而是关于如何跟踪导致请求发生缓慢的应用程序文件。

The most efficient way for counting large tables is that you should be storing the count in a table somewhere else and increasing/decreasing that value when required, that way you're only querying a single cell and a 51second query becomes less than 1 second. 计算大型表的最有效方法是,您应该将计数存储在其他位置的表中,并在需要时增加/减少该值,这样您只需查询单个单元格,51秒查询的时间不到1秒。

I know it feels like a redundant thing to do but it is the most efficient and optimal way 我知道感觉这是多余的事情,但它是最有效和最佳的方式

There are topics around that suggest querying the INFORMATION_SCHEMA but that doesn't help at all given your need for WHERE and everything else is just as inefficient as your issue here. 有些主题建议查询INFORMATION_SCHEMA,但鉴于您对WHERE的需求,这根本无济于事,其他一切与您的问题一样低效。

All you need is the current count, a place to store it, functionality to increase/decrease it and you're good to go 您所需要的只是当前的计数,存储它的地方,增加/减少它的功能以及您的好处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM