I'm using PHP and MYSQL(innodb engine).
As MYSQL reference says, selecting with comparison of one column and ordering by another can't use our considered index.
I have a table named News
.
This table has at least 1 million records with two important columns: time_added
and number_of_views
.
I need to select most viewed records from last n
hours. What is the best index to do this? Or is it possible to run this kind of queries very fast for a table with millions of records?
I've already done this for "last day", meaning I can select most viewed records from last day by adding a new column (date_added
). But if I decide to select these records from last week, I'm in trouble again.