:: DEVELOPER ZONE
In some cases, MySQL handles a query differently when you are
using LIMIT and not using row_countHAVING:
If you are selecting only a few rows with LIMIT, MySQL
uses indexes in some cases when normally it would prefer to do a
full table scan.
If you use LIMIT with row_countORDER BY, MySQL ends the
sorting as soon as it has found the first row_count rows of the sorted
result, rather than sorting the entire result. If ordering is done by using
an index, this is very fast. If a filesort must be done, all rows that
match the query without the LIMIT clause must be selected, and most
or all of them must be sorted, before it can be ascertained that the first
row_count rows have been found. In either case, once the rows have
been found, there is no need to sort any remainder of the result set, and
MySQL does not do so.
When combining LIMIT with row_countDISTINCT, MySQL stops
as soon as it finds row_count unique rows.
In some cases, a GROUP BY can be resolved by reading the key in order
(or doing a sort on the key) and then calculating summaries until the
key value changes. In this case, LIMIT does not calculate any
unnecessary row_countGROUP BY values.
As soon as MySQL has sent the required number of rows to the client, it
aborts the query unless you are using SQL_CALC_FOUND_ROWS.
LIMIT 0 always quickly returns an empty set. This is useful
to check the query or to get the column types of the result columns.
When the server uses temporary tables to resolve the query, the
LIMIT is used to calculate how much space is required.
row_count
© 1995-2005 MySQL AB. All rights reserved.

User Comments
Add your own comment.