MYSQL order by排序导致效率低小优化
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,有一个主表left join 同一个小表两次分页语句,因为order by 导致执行时做排序,从执行计划中Using filesort ,以及profile中creating sort index 耗
千家信息网最后更新 2025年11月07日MYSQL order by排序导致效率低小优化

有一个主表left join 同一个小表两次分页语句,因为order by 导致执行时做排序,从执行计划中Using filesort ,以及profile中creating sort index 耗时可以看出。

从trace文件可以看出filesort的计算:
"join_execution": { "select#": 1, "steps": [ { "filesort_information": [ { "direction": "desc", "table": "`topxxx` `t`", "field": "create_date" } ] /* filesort_information */, "filesort_priority_queue_optimization": { "limit": 20, "rows_estimate": 2302749, "row_size": 264, "memory_available": 4194304, "chosen": true } /* filesort_priority_queue_optimization */, "filesort_execution": [ ] /* filesort_execution */, "filesort_summary": { "rows": 21, "examined_rows": 216594, "number_of_tmp_files": 0, "sort_buffer_size": 5712, "sort_mode": "" } /* filesort_summary */ } ] /* steps */ } /* join_execution */ } 后面通过索引加入排序字段后减去排序操作,排序字段放在索引的最前面。
create index idx_topxxx1 on topic (create_date desc,is_del,is_en);
trace 中可以看出排序使用了索引。
"reconsidering_access_paths_for_index_ordering": { "clause": "ORDER BY", "index_order_summary": { "table": "`topic` `t`", "index_provides_order": true, "order_direction": "desc", "index": "idx_topxxx1", "plan_changed": true, "access_type": "index" } /* index_order_summary */ } /* reconsidering_access_paths_for_index_ordering */ }, {以此记录。
排序
索引
字段
文件
语句
效率
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络技术在企业中的应用
记录网络安全行为儿童画
龙之谷登录服务器连接不上
栖霞区一站式软件开发售后服务
国际软件开发标准
图书出租管理系统数据库设计
网络安全工作检查工作总结
我国第一次提出网络安全法
机柜 服务器 安装
网络安全第五空间第二集
软件开发 t3等级
贺信模板软件开发
td350服务器能装8t硬盘吗
云服务器低价
高中生网络安全知识教育教案
电脑有地址连不上服务器
姑苏区信息化网络技术联系方式
手机基岩版服务器推荐1.16
bcv 技术数据库
navicat数据库字符表
时间戳怎么存数据库
天津 银行软件开发中心待遇
我的世界服务器不兼容的服务端
上海视频安防软件开发价格
无锡大数据服务器供货厂
工作表自动提取数据库
四川实用erp软件开发
软件开发辅助工具下载
数据库设置外键关键字
服务器系统安全加固软件