Home » Performance » MySQL » Does MySQL optimize UNION with a LIMIT clause?
Does MySQL optimize UNION with a LIMIT clause? [message #1758] Fri, 07 September 2007 06:46 Go to previous message
Spuerhund  is currently offline Spuerhund
Messages: 4
Registered: August 2007
Junior Member
Assume i have a query like:
(SELECT a FROM t1)
UNION ALL
(SELECT a FROM t2)
ORDER BY a LIMIT 10;

Will MySQL be so clever and execute it in the same way (and time) as:
(SELECT a FROM t1 LIMIT 10)
UNION ALL
(SELECT a FROM t2 LIMIT 10)
ORDER BY a LIMIT 10;

In other words:
will the limit clause from the outer UNION statement be applied to the inner SELECT queries automatically? Otherwise the inner queries might return a lot (millions) of rows, although only the first 10 rows have a chance to appear in the final result.

Read Message
Read Message
Previous Topic:mysql on windows decreasing perf
Next Topic:CPU 100%
Goto Forum:

  



Current Time: Fri Dec 5 11:46:25 EST 2008

Total time taken to generate the page: 0.24244 seconds
.:: Contact :: Home :: MySQL Support by Percona.com ::.

Powered by: FUDforum 2.7.5.
Copyright ©2001-2006 FUD Forum Bulletin Board Software

MySQL Performance | Forum authority Badge