二、mysql优化
一、expain计划分析
二、创建索引
三、具体优化
1、max
一般创建索引解决

2、count
count统计时,如果是count(*),则会把空null行也统计进去,count(字段名),则不会把null字段统计进去,创建索引和max一样
3、order by,排序如何避免using filesort

1、第一种情况分析,建立索引,顺序如下 (name,age,salary)

2、第三种情况

4、group by,分组如何避免using temporary,其遵守的规则与order by 一样
5、limit
6、in与exists,小表驱动大表
连接5次,操作5000次,连接最消耗资源的
for(int i=0; i<5; i++){
for(int i=0; i<5000; i++){
}
}select * from t1 where id in (select id from where t2)
执行顺序是,先t2,再t1,t2是小表,t1是多大表
for(t2){
for(t1){
}
}select * from t1 where exist (select 1 from where t2.id = t1.id)
执行顺序是,先t1,再t2,t2是小表,t1是多大表,所以这种就会t1大表驱动小表,不推荐
for(t1){
for(t2){
}
}7、索引失效的条件
相关推荐
ribavnu 2020-11-16
要啥自行车一把梭 2020-11-12
vitasfly 2020-11-12
康慧欣 2020-09-10
liuweiq 2020-09-09
moyekongling 2020-11-13
wangshuangbao 2020-11-13
苏康申 2020-11-13
vivenwan 2020-11-13
云中舞步 2020-11-12
kuwoyinlehe 2020-11-12
minerk 2020-11-12