Well, the order in which the queries are made doesn't matter. The query with
LIMIT is always slower than the one
without it. When I used EXPLAIN SELECT... I actually
found that MySQL uses temporary table for the query with
the DISTINCT / LIMIT combination. I presume this slows it down.
Be well :)
George
----- изходно съобщение -----
От: Gerald Clark <[EMAIL PROTECTED]>
Тема: Re: distinct / limit optimization
>Because it wasn't in system cache yet?
>
>X Gogo wrote:
>
>> Hi,
>>
>> I've tried the folowing query:
>> SELECT DISTINCT column1 FROM table1 LIMIT 10;
>> and got the result for 0.23 sec.
>> Then I've tried the same query without limit:
>> SELECT DISTINCT column1 FROM table1;
>> and got the result for 0.01 sec. which is some 23 times
>> faster. There are about 10000 rows in table1 and column1
>> has an index. I've read in the manual that MySQL uses optimization when
>you
>> combine DISTINCT with LIMIT n that would make it stop as soon as it finds
>n
>> unique rows.
>> Why then the first query that uses LIMIT is considerably slower?
>>
>> George
>> ----
>> Безплатна пощенска служба http://mail.Rambler.bg/
>>
>> ---------------------------------------------------------------------
>> Before posting, please check:
>> http://www.mysql.com/manual.php (the manual)
>> http://lists.mysql.com/ (the list archive)
>>
>> To request this thread, e-mail <[EMAIL PROTECTED]>
>> To unsubscribe, e-mail
><[EMAIL PROTECTED]>
>> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>
>--
>Gerald L. Clark
>[EMAIL PROTECTED]
>
----
Безплатна пощенска служба http://mail.Rambler.bg/
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php