I have a fairly large table (up to 100,000 rows) that I need to display systematically.
Basically, I need to show 50 entries per page up to any unlimited number of pages.
here's the core of my current primary query
SELECT * from table1 WHERE value<5 ORDER BY id1 DESC, id4 LIMIT 50
It can also have different ORDER BY criteria, depending on how the user wants it displayed.
ORDER BY id1 DESC, id4 (default)
ORDER BY id2, id4 (common)
ORDER BY id3, id4 (infrequent)
I have an index on id1 on id2 and on id3. id4 has a relatively small range and wouldn't benefit to index anyway.
My problem is that even tho I am not indexing ID4, MySQL simply REFUSES to index on id1 when I try to sort it DESC . This is a documented "feature" and is destroying my ability to optimize the query.
ORDER BY id1 runs in 0.01 seconds
ORDER BY id1 DESC runs in 1.55 seconds
But without re-writing all the data, I HAVE to sort one column ascending and one column descending. If I can't do that, it would be necessary to write code to restructure the data itself. I don't want to do that if I can avoid it.
Any hints?
Thanks,
Eric