《基于ORACLE SQL优化》读书笔记-表的连接方式

NL: 向量I/O 把原先的一批单块读组合起来,用一个向量I/O去批量处理。

笛卡尔连接 MERGE JOIN CARTESIAN: 大部分情况为SQL中漏掉连接条件。

反连接:外部WHERE 条件中NOT EXISTS ,NOT IN 或是<>ALL的子查询转成对应的反连接。

NOT EXISTS和<>ALL对NULL值敏感,一但子查询中有NULL,整个结果都是NULL。

半连接:会去重复。找到一条合条件的记录就停止搜索被驱动表。把外部WHERE 中含有EXISTS,IN或是=ANY的子查询转换成半连接。


create table t21(col1 number,col2 varchar2(1));
create table t22(col2 varchar2(1),col3 varchar2(2));
 
insert into t21 values(1,'A');
insert into t21 values(2,'B');
insert into t21 values(3,'C');
insert into t22 values('A','A2');
insert into t22 values('B','B2');
insert into t22 values('C','C2');
COMMIT;
 
create index indx_t2 on t22(col2);
 
select /*+ ordered use_nl(t22)*/t21.col1,t21.col2,t22.col3from t21,t22 where t21.col2 = t22.col2;
 
select /*+ optimizer_features_enable('9.2.0') ordereduse_nl(t22)*/t21.col1,t21.col2,t22.col3 from t21,t22 where t21.col2 = t22.col2;
 
 
select * from t21 where col2 not in(select col2 from t22);
 
insert into t21 values(4,null);
update t22 set col2 = 'D' where col3 ='C2';
commit;
insert into t22 values(null,'E2');
commit;
select * from t21 where col2 not in (select col2 from t22);
select * from t21 where col2 <> all (select col2 fromt22);
select * from t21 where not exists (select 1 from t22 wherecol2 =t21.col2);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值