I am wondering if my theory is right here so looking for some advice from MySQL gurus.
I have a table I have redesigned to just include various elements user SELECT queries can search against. There are many permutations on the WHERE clause and then a few permutations they could want ORDER BY.
Creating multi indexes for all is pretty much impossible as I see it and slowness can come from the ORDER BY when the table has 1 million+ rows.
My idea is to create versions of the results duplicated in other tables but use ALTER TABLE to do an ORDER BY the various ways a user can ORDER BY.
Then via application know which order the user wants and use that table accordingly. Then indexes would only be needed on the WHERE columns utilising leftmost.
Is this a reasonable way to do it to increase performance and sustainable if the tables are only updated once and copied across and when updated recopied?
Of course im making the assumption that mysql returns rows via LIMIT in the order of the table sort if no ORDER BY in the SELECT statement is declared. This would mean not needing to stick the ORDER BY in the SELECT query.
eg SELECT * FROM table_order_x WHERE x = 1 AND y = 2 AND z = 3 LIMIT 15000,25; relying on the order from the table sort.
Would this work or has anyone had to come up with something similar? I’m trying to think outside the box a bit.
this does not work this way. Order is not guaranteed in a selected list unless ORDER BY is used.
I think a bigger problem for you to contemplate is why does the user need 1 million rows of returned data, what good does that do them? perhaps figuring a way to summarize to something useful would allow you to optimize a bit.
(p.s. the ORDER does not occur until AFTER the result set is determined, so the entire rowset in the table is not somehow pre-ordered before the query is run)