Query optimization in case of TIMESTAMPDIFF I have a table where I need to delete all rows older than 5 hours. Currently I'm doing:

delete from my_table 
where TIMESTAMPDIFF(HOUR, from_unixtime(round(created_on/1000)), now()) &gt; 5


The created_on column is a time stamp stored in milliseconds. I think adding an index on created_on column won't help since the query has a computed value (correct me if I'm wrong).

The delete statement works fine for smaller data sets, however for larger data sets (30-40k rows) it often gets stuck. Why does the delete statement get stuck for large data sets and how can I improve performance?
You should move all the calculations to one side of the comparison:

WHERE created_on &lt; (unix_timestamp(now()) - 5*60*60) * 1000


5*60*60 equals 5 hours