SQL优化 第八章 案例模拟 8.4 Merge Join验证

8.4.1 构造数据环境

create sequence SEQ_TEST

minvalue 1

maxvalue 999999999999999999999999999

start with 1

increment by 1

cache 50;

drop table test1;

drop table test2;

create table test1 as select SEQ_TEST.nextval as id, d.* from dba_objects d;

insert into test1 select SEQ_TEST.nextval as id, d.* from dba_objects d;

--反复插入,构造百万级别以上大表

create table test2 as select  t.* from test1 t;

create index ix_test1_01 on test1(id);

create index ix_test2_01 on test2(id);

8.4.2 Hash Join和Merge Join执行计划比较

select count(*) from test1 t1,test2 t2 where t1.id=t2.id;

select /*+ USE_MERGE(T1 T2)*/ count(*) from test1 t1,test2 t2 where t1.id=t2.id;

因为连接列有索引,此时走Merge Join性能好于Hash,因为主表返回数据量超大,Nested Loop就不用考虑了。

发布了51 篇原创文章 · 获赞 4 · 访问量 4254

猜你喜欢

转载自blog.csdn.net/songjian1104/article/details/91963036
今日推荐