MySQL query taking too long to execute

index-tuningMySQLphpmyadmin

My MySQL query is taking around 20 minutes to execute which I feel is excessive.

SELECT 
  hyp_id,MAX( player_count ) AS MAXPLAYERCOUNT
  , MAX( viewer_count ) AS MAXVIEWERCOUNT
  , SUM( player_count ) AS TOTPLAYER
  , SUM( viewer_count ) AS TOTVIEWER 
FROM player_count_log 
WHERE 
  DATE(added_time) = CURDATE() 
GROUP BY hyp_id 
ORDER BY  hyp_id

The player_count_log table contains over 63 million records with ~18k added every hour.

Here are screenshots of db and indexes

screenshot of the database

screenshot of the indexes

Best Answer

DATE(added_time) = CURDATE() 

is the root of some of the evil

Do not "hide" a column (added_time) inside a function (DATE) if want an index to be used.

If added_time is a DATE, then you can simply do

added_time = CURDATE()

If it is a DATETIME or TIMESTAMP, then do

added_time >= CURDATE() AND
added_time  < CURDATE() + INTERVAL 1 DAY

Then your INDEX(added_time) can be used.