索引使用;
1、not in;某列重复数据过多就直接走全表扫码了;隐式类型转换;函数;or如果有一列没有加索引则不走索引;避免select *;尽量走覆盖索引
2、使用联合索引而不是单列索引,如果是单列索引:
数据库会选择一个最优的索引(辨识度最高索引)来使用,并不会使用全部索引 ;
3、索引量>5个会影响性能;
4、使用exists作为筛选条件效果还是很不错的:
SELECT
a.id,
a.area_code,
a.bill_code,
a.NAME,
a.credit_level,
a.without_approval,
a.apply_credit_days,
a.recommend_credit_limit,
a.recommend_credit_days,
a.STATUS,
a.model_type,
a.create_date,
a.confirm_date,
a.operator,
a.dept_code,
b.peopleFollow mgr_emp_code,
a.current_credit_level,
a.current_credit_limit,
a.current_credit_days,
c.emp_code head_receiver,
'857767' empCode
FROM
enterprise_customer_reassess_record a
LEFT JOIN sasp_ccm_business_account b ON a.bill_code = b.businessAccount
LEFT JOIN cc_area_charge c ON a.area_code = c.area_code
LEFT JOIN tm_department_ccm d ON a.dept_code = d.DEPT_CODE
WHERE
1 = 1
AND (
1 = 1
AND EXISTS (
SELECT
1
FROM
cc_emp_data_right x
WHERE
1 = 1
AND x.`emp_code` = '857767'
AND (
x.`dept_code` = '001'
OR d.`dept_code` = x.`dept_code`
OR d.`DIVISION_CODE` = x.`dept_code`
OR d.`AREA_CODE` = x.`dept_code`
OR d.`HQ_CODE` = x.`dept_code`
)
)
OR b.peopleFollow = '857767'
)