sql优化:
嵌套for循环:长度小的放外层,长度大的放内层多表联结查询优化:左外连接,给左表加索引,on条件 小表放左 大表放右where条件后常用字段加索引复合索引不要跨列或无序使用。复合索引尽量全部都使用。(a,b,c) where a='' and b='' and c='';索引上不要进行操作(计算、函数、类型转换)复合索引 左边索引失效 右边的都失效。!= 、<、> 、is null 、is not null 会使索引失效以%开头的模糊查询索引失效索引覆盖可以挽救一部分索引like失效问题 select name from teacher where name like '%x%';不要使用or 否则索引失效,or会将其左边的列索引失效。exits 用法:create table emplyee ( eid int, name varchar(33), depid int);create table dept( did int, name varchar(23))查询员工表中有部门的员工:select * from emplyee where exists(select * from dept where emplyee.depid=dept.did);如果主查询的数据集大,就使用in,如果著查询的数据集小,就使用exist;
转载于:https://www.cnblogs.com/mryangbo/p/11247189.html