SQL子查询中IN太多,该如何优化让查询速度更快?

SELECTLIFT_INFO_IDFROMlc_lift_association<where><iftest="param.platforms!=null">ANDPL... SELECT LIFT_INFO_ID FROM lc_lift_association
<where>
<if test="param.platforms != null">
AND PLATFORM_ID IN
<foreach item="id" index="index" collection="param.platforms"
open="(" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.userUnits != null">
AND USER_UNIT_ID IN
<foreach item="id" index="index" collection="param.userUnits"
open="(" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.smantanceUnits != null">
AND SMANTA_UNIT_ID IN
<foreach item="id" index="index" collection="param.smantanceUnits"
open="(" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.manufacturingUnits != null">
AND MANUFA_UNIT_ID IN
<foreach item="id" index="index" collection="param.manufacturingUnits"
open="(" separator="," close=")">
#{id}
</foreach>
</if>
<if test="param.inspecAgencys != null">
AND INSPEC_ANGECY_ID IN
<foreach item="id" index="index" collection="param.inspecAgencys"
open="(" separator="," close=")">
#{id}
</foreach>

</if>
<if test="param.qualitSuperBureaus != null">
AND QUALIT_SUPER_BUREAU IN
<foreach item="id" index="index" collection="param.qualitSuperBureaus"
open="(" separator="," close=")">
#{id}
</foreach>
</if>
</where>
) assoc ON d.ID = assoc.LIFT_INFO_ID
展开
 我来答
百依连城
2016-06-22 · TA获得超过242个赞
知道小有建树答主
回答量:185
采纳率:66%
帮助的人:100万
展开全部

in可以用exists代替,原则上集合数少用IN比较快,集合数据大用exists比较好


追问
  • 请问具体该如何替换啊?我试过好像不行!!!

本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式