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 展开
<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 展开
1个回答
展开全部
in可以用exists代替,原则上集合数少用IN比较快,集合数据大用exists比较好
追问
请问具体该如何替换啊?我试过好像不行!!!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
柚鸥ASO
2024-03-16 广告
2024-03-16 广告
在ASO优化过程中,确定关键词的一般步骤如下:1. 确定有效关键词:首先需要了解目标市场的热度,过滤掉低热度的关键词,例如搜索次数小于4605的词,因为平均一天只有一次搜索。这些低热度的词大部分是关键词覆盖的长尾搜索词,无需过多关注。2. ...
点击进入详情页
本回答由柚鸥ASO提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询