mysql 分页数据错乱

最近在使用mysql 分页查询数据的时候发现返回的数据与预期的不一样,显示数据重复错乱。

官方文档 有这样一句话

If multiple rows have identical values in the ORDER BY columns, the server is free to return those rows in any order, and may do so differently depending on the overall execution plan. In other words, the sort order of those rows is nondeterministic with respect to the nonordered columns.

One factor that affects the execution plan is LIMIT, so an ORDER BY query with and without LIMIT may return rows in different orders. Consider this query, which is sorted by the category column but nondeterministic with respect to the id and rating columns:        

说明当order by 列中有重复值的时候,mysql server 会看自己心情随机处理返回结果。

当使用mysql 进行分页查询出现数据不一致问题时候 可以看看order by 后面列数据是否有重复值

参考文献:数据库内核月报 - 2015 / 06

原文地址:https://www.cnblogs.com/gsjlovenet/p/10533907.html