一. 单表查询
order by
order by 字段建立索引的前提是where后的字段也建立了索引(避免出现Using filesort)
group by
group by 可以建立索引,并不需要where后的字段建立索引(避免出现Using temporary)
where a = 3 and b > 4 and c = 5
使用到a和b, c不能用在范围之后,b断了
where a = 3 and b like 'k%kk%' and c = 4
Y,使用到a,b,c
二.多表
inner join
选择表列数比较大的表,进行创建索引(表大的)
left join
只能是左表进行全表扫描
使用left join .. where ... is null 代替 not in (子查询)