两点:避免全表扫描和添加索引
1.如何避免全表扫描
a.避免使用select * from ~
b.避免在where语句中出现null,可以将null替换为0
select ~ from ~ where ~=null;
select ~ from ~ where ~=0;
c.避免在where语句中出现模糊查询和!=
select ~ from ~ where ~like '%a';
select ~ from ~ where ~ != num;
2.添加索引
a.在使用order by语句中可以不用排序
b.在使用where语句时可以查询索引