有下面这么一段SQL 检索内容较多,就这边我就直接用1了。
select 1
from
IC_MEMBER_MC this_
inner join
IC_MEMBER mb4_
on this_.COMPANY_CODE=mb4_.COMPANY_CODE
and this_.MEMBER_ID=mb4_.MEMBER_ID
inner join
IC_CUSTOMER ct3_
on this_.COMPANY_CODE=ct3_.COMPANY_CODE
and this_.MEMBER_ID=ct3_.MEMBER_ID
inner join
IC_MC mc1_
on this_.COMPANY_CODE=mc1_.COMPANY_CODE
and this_.FRAME_NO=mc1_.FRAME_NO
and this_.ENGINE_NO=mc1_.ENGINE_NO
inner join
IC_MODEL mcmodel2_
on mc1_.COMPANY_CODE=mcmodel2_.COMPANY_CODE
and mc1_.MODEL_CODE=mcmodel2_.MODEL_CODE
and mc1_.SPEC_CODE=mcmodel2_.SPEC_CODE
where
this_.COMPANY_CODE="6548"
and this_.DEALER_CODE="SASA05"
and (
(
ct3_.DOWNLOAD_COUNT=0
and ct3_.FOLLOW_UP_COUNT=0
)
or (
ct3_.FOLLOW_UP_FINISH_DATE is not null
and ct3_.FOLLOW_UP_FINISH_DATE between "19000101" and "20110418"
)
)
and ct3_.REMOVE_FLAG="0"
order by
mb4_.CITY asc,
mb4_.DISTRICT asc,
mb4_.SUB_DISTRICT asc
IC_MEMBER表 有复合索引 “COMPANY_CODE”“MEMBER_ID ” 数据量为 6,000,000
IC_CUSTOMER 有复合索引 “COMPANY_CODE”“MEMBER_ID ” 数据量为 5,000,000
IC_MC 有复合索引 “COMPANY_CODE”“FRAME_NO” “ENGINE_NO” 数据量为 5,000,000
IC_MODEL 有复合索引 “COMPANY_CODE”“MODEL_CODE”“SPEC_CODE”数据量为 2,582
IC_MEMBER_MC 有复合索引 “COMPANY_CODE”“DEALER_CODE” 数据量为 5,000,000
这一段SQL要跑2min,请问各位大侠,有没有什么优化的方案写法,让这个跑快点
------解决方案--------------------
这个看起来太费劲,懒得看,不过你自己可以通过执行计划来看是否能够有优化的余地
set explain on avoid_execute;
select ...
你自己查看这个语句的执行计划再说
------解决方案--------------------
ct3_.DOWNLOAD_COUNT=0
and ct3_.FOLLOW_UP_COUNT=0
)
or (
ct3_.FOLLOW_UP_FINISH_DATE is not null
and ct3_.FOLLOW_UP_FINISH_DATE between "19000101" and "20110418"
使用union方法试一下
------解决方案--------------------
wehere 条件中要多用含有索引的栏位,这样速度会提供很多的。