前言
记录自己在工作开发中遇到的SQL优化问题
1、避免用in 和 not in
解决方案:
- 用exists 和 not exists代替
- 用join代替
not exists示例
not in:1
select stepId,province_code,polyline from route_step where stepId not in (select stepId from stepIds)
not exists:1
select stepId,province_code,polyline from route_step where not exists (select stepId from stepIds where route_step.stepId = stepIds.stepId)