mysql order by 出现Using filesort的解决办法
2015-03-16 17:43
281 查看
http://blog.csdn.net/yangyu112654374/article/details/4251624
比如一条sql语句
select * from TABLE1 where A1=1 and A2=2 and A3=3 order by A4 ASC;
优化后是这样: select A4,A1,A2 ... FROM TABLE1 where A1=1 and A2=2 and A3=3 order by A4 ASC; 并且给 A4,A1,A2,A3加索引,使用order by A4时,联合索引要将A4放在首位。
SELECT的时候必须出现order by的字段才行
2. 从上面可以看到联合索引,也可以叫多列索引,形如 key ('A1','A2','A3' ,'A4')等的,排序的思路一般是,先按照A1来排序,A1相同,然后按照A2排序,以此类推,这样对于(A1),(A1,A2),(A1,A2,A3)的索引都是有效的,但是对于(A2,A3)这样的索引就无效了。
比如一条sql语句
select * from TABLE1 where A1=1 and A2=2 and A3=3 order by A4 ASC;
优化后是这样: select A4,A1,A2 ... FROM TABLE1 where A1=1 and A2=2 and A3=3 order by A4 ASC; 并且给 A4,A1,A2,A3加索引,使用order by A4时,联合索引要将A4放在首位。
SELECT的时候必须出现order by的字段才行
2. 从上面可以看到联合索引,也可以叫多列索引,形如 key ('A1','A2','A3' ,'A4')等的,排序的思路一般是,先按照A1来排序,A1相同,然后按照A2排序,以此类推,这样对于(A1),(A1,A2),(A1,A2,A3)的索引都是有效的,但是对于(A2,A3)这样的索引就无效了。
相关文章推荐
- mysql order by 造成语句 执行计划中Using filesort,Using temporary相关语句的优化解决
- mysql 出现 1045 access denied for user 'root'@'localhost' using password yes 解决办法
- Linux 下安装mysql 出现libncurses.so.5 is needed by MySQL-client-5.6.22-1.el6.i686解决办法
- mysql出现GROUP BY clause错误解决办法
- mysql中出现 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)的解决办法
- MYSQL 新版出现" Client does not support authentication protocol requested by server; consider upgrading MySQL client"解决办法
- mysql5.7中的一个update order by排名问题解决办法(一条sql搞定排名)
- MySQL登录时出现 Access denied for user 'root'@'xxx.xxx.xxx.xxx' (using password: YES) 的原因及解决办法
- MySQL登录时出现 Access denied for user 'root'@'xxx.xxx.xxx.xxx' (using password: YES) 的原因及解决办法
- MySQL5.6出现”Using a password on the command line interface…”解决办法
- dbexpress 4 + mysql 5 出现Too more connections的错误,解决办法说明
- Crystal report 出现maximum report processing jobs limit configured by your system administrator has been reached错误的解决办法.
- mysql出现manager of pid-file quit whitout updateing file的解决办法
- mysql 创建函数时出现 Error Code : 1418 错误解决办法
- Linux rar 安装出现rar: /lib/i686/nosegneg/libc.so.6: version `GLIBC_2.7' not found (required by rar) 的解决办法
- redhat安装pure-ftpd+mysql时出现libmysqlclient错误的解决办法
- NFS无法挂载,出现错误:reason given by server: Permission denied的解决办法
- Setting environment for using Microsoft Visual Studio 2008 x86 tools出现此时不应有的解决办法
- linux下安装mysql源码包出现configure: error: No curses/termcap library found的解决办法
- mysql4.1以上版本连接时出现Client does not support authentication protocol问题解决办法