我正在使用 heidiSQL 编辑器运行 mySQL 查询。当它告诉我我的查询时间时,它有时还会包括网络时间:
1 个查询的持续时间:1.194 秒。(+ 10.078 秒网络)
但它不可能真的是网络,因为一切都在我自己的电脑上?额外的时间是否会随着其他设置而消失,或者我是否需要以通常的方式(重写/返工)提高我的查询性能?当我什至不确定是什么导致性能不佳时,我很难提高查询的性能。
编辑:分析信息
我使用了这个简洁的分析 sql:http ://www.mysqlperformanceblog.com/2012/02/20/how-to-convert-show-profiles-into-a-real-profile/
查询一:
从 my_table_with_100_thousand_rows 中选择 count(*);
“1 次查询的持续时间:0.390 秒。” (这个没有显示任何网络时间,但对于一个简单的计数(*)来说,几乎 0.4 秒似乎很多。)
STATE Total_R Pct_R Calls R/Call
Sending data 0.392060 35.84 1 0.3920600000
freeing items 0.000214 0.02 1 0.0002140000
starting 0.000070 0.01 1 0.0000700000
Opening tables 0.000031 0.00 1 0.0000310000
statistics 0.000024 0.00 1 0.0000240000
init 0.000020 0.00 1 0.0000200000
(shorter times not included)
查询 2:
select * from 4 个多行表,由 primary_key-foreign_key 或索引列连接。
“1 次查询的持续时间:0.156 秒(+ 10.140 秒网络)”(以下时间加起来超过总数?)
STATE Total_R Pct_R Calls R/Call
Sending data 16.424433 NULL 1 16.4244330000
freeing items 0.000390 NULL 1 0.0003900000
starting 0.000116 NULL 1 0.0001160000
statistics 0.000054 NULL 1 0.0000540000
Opening tables 0.000050 NULL 1 0.0000500000
init 0.000046 NULL 1 0.0000460000
preparing 0.000033 NULL 1 0.0000330000
optimizing 0.000028 NULL 1 0.0000280000
(shorter times not included)
查询 3:与查询 2 相同,但使用 count * 而不是 select *
“1 个查询的持续时间:10.047 秒。”
STATE Total_R Pct_R Calls R/Call
Sending data 10.050007 NULL 1 10.0500070000
(shorter times not included)
在我看来,如果它必须显示很多行,它在“持续时间”中包括网络时间,但这并不意味着如果它不必显示行,我可以减去这个时间。这是真正的查询时间。这看起来对吗?