如果您将LIMIT row_count与ORDER BY一起使用,则MySQL结束排序为
一旦找到排序结果的前row_count行,
而不是对整个结果进行排序.如果订购是通过使用
索引,这是非常快的.如果必须执行文件排序,则所有
必须选择不带LIMIT子句的匹配查询,并且大多数或
必须先对它们全部进行分类,然后才能确定
找到第一个row_count行.无论哪种情况,在
已找到初始行,无需对任何剩余行进行排序
结果集,而MySQL则没有.
If you use LIMIT row_count with ORDER 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, after the
initial rows have been found, there is no need to sort any remainder
of the result set, and MySQL does not do so.
因此,在应用LIMIT
之前,知道整个结果集似乎是可能.但是MySQL会尝试所有无法做到的事情.而且,您可以通过提供与查询匹配的有用索引来提供帮助.
So it looks like it's possible that the entire result set is known before the LIMIT
is applied. But MySQL will try everything it can not to do so. And you can help it by providing useful indexes that match your queries.
此外,如果未对集合进行排序,则在将足够的行流式传输到结果集后,它将终止SELECT
操作.
Furthermore, if the set is not sorted it terminates the SELECT
operation as soon as it's streamed enough rows to the result set.
这篇关于如何在SQL中使用"LIMIT"参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!