This is a discussion on Slow query within the MySQL Database forums, part of the Database Forums category; Hi all, I have a query that counts lines with certain properties, grouped by day. But the time is stored ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi all,
I have a query that counts lines with certain properties, grouped by day. But the time is stored in seconds, therefore I do it as follows: EXPLAIN SELECT received_time as raw_date, DATE_FORMAT(FROM_UNIXTIME(received_time), '%d. %M %Y') AS format_date, sum(case when server_state=5 and outcome=1 then 1 else 0 end) as wu_success, sum(cpu_time/3600) as cpu_hours, sum(case when server_state=5 and outcome!=1 and outcome!=4 then 1 else 0 end) as wu_other FROM result WHERE received_time>1162277941 GROUP BY format_date DESC ORDER BY raw_date DESC: *** row 1 *** table: result type: range possible_keys: idx_received_time key: idx_received_time key_len: 4 ref: NULL rows: 110388 Extra: Using where; Using temporary; Using filesort That works but the query takes several minutes to complete. Is it possible to speed it up? The table result holds about 250 000 lines and it has an index on the received_time column but I'm not sure if the index really helps in that case. Thx. Best Bernahrd |