EXPLAIN EXTENDED

How to create fast database queries

Archive for May 15th, 2009

Ordering UNION’s

Comments enabled. I *really* need your comment

From Stack Overflow:

When I optimize my 2 single queries to run in less than 0.02 seconds and then UNION them the resulting query takes over 1 second to run.

Also, a UNION ALL takes longer than a UNION DISTINCT.

I would assume allowing duplicates would make the query run faster and not slower.

Am I really just better off running the 2 queries separately? I would prefer to use the UNION.

This kinds of things happen when the queries employ ORDER BY along with LIMIT.

Let's create the sample tables and see what is happening:
Read the rest of this entry »

Written by Quassnoi

May 15th, 2009 at 11:00 pm

Posted in MySQL