I have a table with a datetime column that I ORDER BY.
Whatever I do, I keep getting “using where; using filesort” from the EXPLAIN.
Is there no way of getting an ORDER BY on datetime columns to NOT use filesort?
The query is very simple and looks like so:
SELECT * FROM table1 WHERE creator_id = 1 AND user_id != 1 ORDER BY created DESC LIMIT 5
index is on creator_id and user_id I see no reason to put an index on created since it’s basically always unique thus would create an index on all items i.e. as big as the table.
edit: I should mention I have tried putting index on created as well, same result.
If you create compound index on
(creator_id, created), your query should work much faster.Query planner will use first part of the index:
creator_idto satisfy WHERE constraint, and second part ofcreatedto sort.