其他
分页场景慢?MySQL的锅!
The following article is from 牛牛码特 Author 牛牛码特
从一个问题说起
select * from t_record where age > 10 offset 10000 limit 10
小白直觉作答
继续解答
select * from t_record where age > 10 offset 10000 limit 10
聚簇索引:包含主键索引和对应的实际数据,索引的叶子节点就是数据节点;
辅助索引:也叫二级节点,其叶子节点还是索引节点,并没有完整的数据,仅包含了索引值本身和主键id,用主键id反查聚蔟索引才能获取完整数据。
方案一:产品上绕过
select * from t_record where id > last_id limit 10
方案二:正面刚
select * from t_record id in
(select id from t_record where age > 10 offset 10000 limit 10)