For the problem below, I got the query working. But when I am running the above query on a table having 2 million records, the MySQL process seems to hog the CPU with 100% utilization. I have been waiting for more than 15 minutes and still the query is running. Are there any performance tweaks which can improve this?
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;
System is running with Intel(R) Xeon(R) CPU X3430 @ 2.40GHz CentOS 5.6 with 8GB of RAM.
Update with EXPLAIN output:
*************************** 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)
What indices do you have in your tables? Try prepending an
EXPLAINso see if indices are actually used.