docs(mysql): add the order by condition to the pagination statement.#2866
Open
bengbengbalabalabeng wants to merge 1 commit into
Open
docs(mysql): add the order by condition to the pagination statement.#2866bengbengbalabalabeng wants to merge 1 commit into
bengbengbalabalabeng wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修改
ORDER BY条件测试示例:
MySQL 在线测试平台
当表中出现多个二级索引(非自然顺序类型),子查询
select id from EMPLOYEE limit 100, 10执行时,优化器发现:因为二级索引树通常比主键索引树更矮、更窄(占用的磁盘空间和内存更小),MySQL 优化器为了追求极致的 I/O 效率,几乎必然会选择扫描 idx_dept 索引树(在线测试平台结果也是如此)。
但是,idx_dept 索引树是按照 dept 字段的字母顺序 排序的,里面的 id 是完全无序杂乱的。这时候你拿到的前 100 个 id,其物理顺序是跟着部门名称排序的。你的分页顺序瞬间全部乱套,每次翻页都会出现严重的数据重复或遗漏。