code1:
with tmp_1 as
(
select .....
)
select * from a where 
not 
exists (select * from tmp_1 t where t.code=b.code);
code2:
create table tmp_1 nologging as 
select .....
;
select * from a where 
not 
exists (select * from tmp_1 t where t.code=b.code);上面两段代码中一个是内嵌视图tmp_1,另一个是表tmp_1(且无索引),
形成这两个tmp_1的select 语句是一样的,也就是说
两个tmp_1中的记录是相同的,
表a和tmp_1都是100万条以上的记录。
问题:
这两段代码执行起来在速度上有什么区别?为什么?

解决方案 »

  1.   

    里面‘not 
    exists (select * from tmp_1 t where t.code=b.code);’应为
    not 
    exists (select * from tmp_1 t where t.code=A.code);
      

  2.   

    code1和code2都应是:
    not  
    exists (select * from tmp_1 t where t.code=A.code);
      

  3.   

    code2中既然create table了,就对code字段建个索引,速度会快很多
      

  4.   

    code2 快, 因为code 1在数据量大时要把数据放到一个临时表中
      

  5.   

    楼主的效率要算上建表的时间吧?如果不计算建表的开销,很明显第二要快,特别是当内嵌视图的查询较复杂时。如果在code2的表上建上索引速度还会提高。