UNION and ORDER BY
Hi,
There is another question I've got.
Lets say I have the following query
(SELECT col1, col2, col3
FROM table
WHERE (col1 = 1) AND col2 BEETWEEN 10 AND 20)
UNION ALL
(SELECT col1, col2, col3
FROM table
WHERE (col1 = 2) AND col2 BEETWEEN 10 AND 20)
ORDER BY col2
There is a multicolumn key defined on table for col1 and col2
If you look at the explain of this query, the UNION RESULT table is using filesort.
Is there a way to optimize that? Because every subquery can be sorted by col2 using index, so I could use a merge sort kind algorithm to order it in a faster way. Does filesort work like that?. If you put ORDER BY inside each subquery Mysql optimizes it away, is there a way to keep them?
Thanks
Ariel
Subject
Views
Written By
Posted
UNION and ORDER BY
2193
August 08, 2005 10:16AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.