Christian Smith wrote:

> Query (2) has an extra condition in the WHERE clause, thus reducing
> the result set size to be sorted. As sorting is probably an
> O(n.log(n)) operation, halving the result set will more than halve
> the time taken to sort, for example. Add that extra condition to
> query (1), and you should get similar results for both queries.

So, If I understood well, sorting is the most time consumpting part of a
query.
LIMIT is applied after all results are gathered (filtered, sorted, and so
on), so getting e.g. 20 sorted records from 20 000 item table takes much
more time than another query 20 sorted records but limited by another WHERE
condition - because sorting is done on much smaller group of records in
second case.

And - if I have to have sorted results as a small (but ordered!) part of big
amount of data - there is no way to make it faster...

Ok, thanks to all for your explanations!
Regards
Adam

Reply via email to