我的查询真的很慢;执行需要17秒。它在Godaddy VPS上达到100%的CPU。有什么想法可以做什么?
此查询:
SELECT
`gps_unit_location`.`idgps_unit`,
MAX(`gps_unit_location`.`dt`) dtmax
FROM `gps_unit_location`
GROUP BY 1
解释
id='1', select type='SIMPLE', table='gps_unit_location', type='index', possible keys=NULL, key='fk_gps2', key len='5', ref=NULL, rows='368668', extra=''
答案 0 :(得分:3)
(idgps_unit, dt)
上的索引可以使查询更快。
您可以通过更改:
来扩展idgps_unit
上的索引
KEY `fk_gps2` (`idgps_unit`),
到
KEY `fk_gps2` (`idgps_unit`, `dt`),
(根据this SO question,key
是index
的同义词。)