oracle的where not in 语句不能应付超大数据量的排查,怎么办
答案:4 悬赏:0
解决时间 2021-02-22 02:06
- 提问者网友:焚苦与心
- 2021-02-21 05:30
oracle的where not in 语句不能应付超大数据量的排查,怎么办
最佳答案
- 二级知识专家网友:冷風如刀
- 2021-02-21 06:19
where not in如果数据量过大,可采用not exists的方式来写语句。
如有以下语句:
select distinct phone_number from zj_jituan_3g where phone_number not in (select phone_number from zj_34g_201512);可改写为:
select distinct a.phone_number from zj_jituan_3g a where not exists
(select 1 from zj_34g_201512 b where a.phone_number=b.phone_number);
如有以下语句:
select distinct phone_number from zj_jituan_3g where phone_number not in (select phone_number from zj_34g_201512);可改写为:
select distinct a.phone_number from zj_jituan_3g a where not exists
(select 1 from zj_34g_201512 b where a.phone_number=b.phone_number);
全部回答
- 1楼网友:深街酒徒
- 2021-02-21 09:11
话说你在哪里用到了not in 了。
使用minus
使用minus
- 2楼网友:一把行者刀
- 2021-02-21 07:44
使用in 或 not in是用不上索引的,可以考虑在小表中使用,而exists或not exists 能用上索引,可以考虑在大数据量表中使用;select mc from 表1 t1 where exists(select 1from 表2 t2 where t1.mc = t2.mc);select mc from 表1 t1 where not exists(select 1 mc from 表2 t2 where t1.mc = t2.mc);楼上推荐答案里应该使用not exists;另外,问题中的2个表按说数据量都不大,即使用 not in 用不上索引全表扫也不应该查不出来,应该检查一下还有没有别的问题。
- 3楼网友:长青诗
- 2021-02-21 06:36
尽量使用exists语句,不要用in
select mc from 表1 t1 where exists(select 1 mc from 表2 t2 where t1.mc = t2.mc)
select mc from 表1 t1 where exists(select 1 mc from 表2 t2 where t1.mc = t2.mc)
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯