0
点赞
收藏
分享

微信扫一扫

Kafka-设计原理

追梦人的自留地 2024-09-06 阅读 28

Oracle优化连接查询速度


今天在使用dblink的时候,多表关联时发现条件中使用 not in 作为条件,会极大的影响查询速度,尤其是not in中的表数据量很大时,简直是一种灾难;经过翻阅资料,找到两种比较好用的方法:

  1. 采用exists模式
  2. 采用Left join模式

样例

select columns from tab1 
where column1 not in (select column1 from tab2);

exists模式

select columns from tab1 where 
not exists(select 1 from tab2 where tab1.column1 = tab2.column1);

exists返回true或false,具体的问题研究建议找一些讲的比较深入的资料,本人才疏学浅,解释不清

Left join模式

select columns from tab1 
left join tab2 on tab1.column1 = tab2.column1
where tab2.column1 is null

左连接,以左表为主,副表tab2中 关联不到的就自动赋值null
不理解可以查下左连接关联的资料画画图
注: is null 可能有坑,建议使用 nvl(trim(tab2.column1),‘自己指定值’) = ‘自己指定值’

举报

相关推荐

0 条评论