MySQL优化----------小技巧

1. 在使用group by时就不再使用索引,而且默认会再次自动排序,如果不想要这种排序,需      要加入:order by null

比如:下面这张表,如果使用group by 分组后,还会自动对分组后的数据进行排序,

 

 explain select * from dept group by dname \G

explain select * from dept group by dname order by null \G

 

 2. 在某些情况下,用left/right join.....on来代替子查询,因为在Mysql中使用join不会在内存       创建临时表

//不建议使用
select * from dept, emp where dept.deptno = emp.deptno

//建议使用
select * from emp left join dept on dept.deptno = emp.deptno

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章