我正在使用超过2百万条记录的"用户"表.查询是:
SELECT * FROM users WHERE 1 ORDER BY firstname LIMIT $start,30
Run Code Online (Sandbox Code Playgroud)
"firstname"列已编入索引.获取第一页非常快,而获取最后一页非常慢.
我使用了EXPLAIN,结果如下:
对于
EXPLAIN SELECT * FROM `users` WHERE 1 ORDER BY `firstname` LIMIT 10000 , 30
Run Code Online (Sandbox Code Playgroud)
我越来越:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE users index NULL firstname 194 NULL 10030
Run Code Online (Sandbox Code Playgroud)
但对于
EXPLAIN SELECT * FROM `users` WHERE 1 ORDER BY `firstname` LIMIT 100000 , 30
Run Code Online (Sandbox Code Playgroud)
我越来越
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE users ALL NULL …Run Code Online (Sandbox Code Playgroud) mysql ×1