oracle什么时候用in什么时候用exists

--用in         
SELECT  m.offer_ins_id,m.subscriber_ins_id 
--select count(*)
FROM ins1.UM_OFFER_xxx M  where m.offer_type = '14' and m.offer_ins_id in(
       select m2.offer_ins_id
          from ins1.UM_BUND_OFFER_REL_xxx M2
         where m2.spec_code = 'PMOfferFamilyMainRoleSpec'
)

--用exists
SELECT  m.offer_ins_id,m.subscriber_ins_id 
--select count(*)
FROM ins1.UM_OFFER_xxx M  where m.offer_type = '14'  and exists (
       select null
          from ins1.UM_BUND_OFFER_REL_xxx M2
         where m2.spec_code = 'PMOfferFamilyMainRoleSpec' and m.offer_ins_id= m2.offer_ins_id
)

select /*+ parallel(8)  */count(*) from ins1.um_subscriber_xxx t
select /*+ parallel(8)  */count(*) from ins1.UM_OFFER_xxx M
SELECT /*+ parallel(8)  */count(*) FROM ins1.UM_BUND_OFFER_REL_xxx M2


--测试结论,明显加了并行查询会提升查询速度
--um_offer_xxx数据量很大,也就两千多万吧
--看了网上结论,说B表小则用in反之用exists

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值