It's very useful to see a blog post about limit performance in the near future.
Limit syntax
SELECT * FROM table LIMIT [offset,] rows | Rows Offset Offset |
The LIMIT clause can be used to force the SELECT statement to return the specified number of records. LIMIT accepts one or two numeric parameters. parameter must be an integer constant. Given two parameters, the first parameter specifies the offset of the first return record row, and the second parameter specifies the maximum number of rows to return records. The initial record line offset is 0 (not 1): MySQL also supports syntax: LIMIT # offset # In order to be compatible with PostgreSQL.
?
1 2 3 4 5 6 7 8 |
mysql>
SELECT *
FROM table LIMIT 5,10; // 检索记录行 6-15
//为了检索从某一个偏移量到记录集的结束所有的记录行,可以指定第二个参数为 -1: mysql>
SELECT *
FROM table LIMIT 95,-1; // 检索记录行 96-
last
.
//如果只给定一个参数,它表示返回最大的记录行数目: mysql>
SELECT *
FROM table LIMIT 5; //检索前 5 个记录行 //换句话说,LIMIT n 等价于 LIMIT 0,n。
|
is limit less a statement and less time consuming?
This is derived from a blog query for the exception problem: the same statement, but the last limit row number is different. Oddly, limit 10 's performance is about 10 times times slower than the Limit 100 statement.
Specific analysis, you can refer to: MySQL An exception query problem tracing