对于下面的问题,我得到了查询。但是当我在一个有 200 万条记录的表上运行上述查询时,MySQL 进程似乎以 100% 的利用率占用了 CPU。我已经等待了超过 15 分钟,但查询仍在运行。是否有任何性能调整可以改善这一点?
select
u.website,
sum(e.ULVolume + e.DLVolume) as volume
from mytable e
left join mytable u on u.PID = e.PID and u.event ='update'
where e.Event = 'end'
group by 1;
系统运行 Intel(R) Xeon(R) CPU X3430 @ 2.40GHz CentOS 5.6 和 8GB RAM。
使用 EXPLAIN 输出更新:
*************************** 1. row ***************************
id: 1 select_type: SIMPLE
table: e
type: ALL possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 2858631
Extra: Using where; Using temporary; Using filesort
*************************** 2. row ***************************
id: 1 select_type: SIMPLE
table: u
type: ALL possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 2858631
Extra: 2 rows in set (0.00 sec)