Mysql 带有Group by的MAX()函数非常慢

Mysql 带有Group by的MAX()函数非常慢,mysql,sql,performance,Mysql,Sql,Performance,我的问题真的很慢;执行需要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

我的问题真的很慢;执行需要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=''
(idgps\u unit,dt)
上建立索引可以大大加快查询速度

您可以通过更改以下内容来扩展
idgps\u单元
上的索引:

KEY `fk_gps2` (`idgps_unit`),


(根据,
索引
的同义词)

添加索引后,是否应运行任何命令重新索引现有数据?数据库将确保索引始终是最新的。仅当您要对磁盘空间进行碎片整理时才需要重新编制索引。您确定不需要重新生成统计信息吗?@Sebas:新创建的索引将具有完美的统计信息。看一看,我们正在进行微调。下一步是调试硬件:-(表中有多少条记录?如解释所示:
rows='368668'
输出中有多少行?
KEY `fk_gps2` (`idgps_unit`, `dt`),