assuming i have a MySQL table with 500 million records within it
it have a column ts , which is indexed and have timestamps as values .
is it efficient doing a
select * from table where ts>=time()-24hours
as well as for last 24 hours/week/month/year ?
or shall i go for nosql ?
I’ve found that MySQL will often throw away indexes when dealing with large date ranges. Your “>=”, which technically a range (ending in “now”), might be an exception for the optimizer since it should be able to jump to the starting point…
If you can stand the time to build the table, use
EXPLAINto see if it’s using the index.Hopefully you don’t need to
SELECT *. If you only need a couple of smaller columns in your results, put them in the index, too, which will keep MySQL from having to read the underlying wider rows from disk.