使用场景,in适合数据量小的时候,exists适合数据量大的时候。

<if test="torqueRecordPageDTO.vinList != null and torqueRecordPageDTO.vinList.size >0">
and exists (
select 1 from (
<foreach collection="torqueRecordPageDTO.vinList" item="item" index="index" separator="union all">
select #{item} as vin
from dual
</foreach>
) a where a.vin = f.record_vin and a.product_id = t1.product_id
)
</if>
<!-- <if test="torqueRecordPageDTO.vinList != null and torqueRecordPageDTO.vinList.size >0">-->
<!-- AND F.record_vin in-->
<!-- <foreach collection="torqueRecordPageDTO.vinList" separator="," item="v" open="(" close=")">-->
<!-- #{v}-->
<!-- </foreach>-->
<!-- </if>-->

原理


mybatis exists 中使用代替in关键字_分布式