《Oracle 高效设计》 读书思考--标量子查询查询性能讨论

      刚看了《oracle 高效设计》的讲到的,说到oracle中有标量子查询,性能要由于关联查询,但是我在SQL server中知道关联查询的性能要优于标量子查询。

     我们来做个测试,看看性能:执行语句:

set  autotrace on
select a.username,count(
* )   from all_users a,all_objects b
where  a.username = b.owner( + )
group by a.username;

   在SQL developer中执行,结果如下:

       5356   recursive calls
         
0   db block gets
      
82152   consistent gets

 

    再执下列语句:

set  autotrace  on
select  a.username,( select   count ( * from  all_objects b  where  b.owner = a.username) cnt
from  all_users a;

    执行结果,如下:

       5371   recursive calls
         
0   db block gets
     
98645   consistent gets

    这时发现,通过执行关联查询的性能要优于标量子查询。估计《Oracle 高效设计》是版本比较低,现在都是用的10gR2的版本有很大改变。

  执行语句如下:

set  autotrace  on
select  a.username, count ( * ), avg ( object_id from  all_users a,all_objects b
where  a.username = b.owner( + ) group   by  a.username; 

  执行结果:

             5371   recursive calls
               
0   db block gets
           
82157   consistent gets

  执行语句:

set  autotrace  on
select  username,to_number(substr(data, 1 , 10 )) cnt,to_number(substr(data, 11 ))  avg   from
(
select  a.username,( select  to_char( count ( * ), ' fm0000000009 ' ||   avg ( object_id from  all_objects b  where  b.owner = a.username) data from  all_users a)

 执行结果:

         5356   recursive calls
           
0   db block gets
        
98556   consistent gets

  执行语句:

set  autotrace  on
create   or   replace  type myType  as  object
(cnt 
number , avg   number );
select  username,a.data.cnt,a.data. avg   from
(
select  username,( select  myType( count ( * ), avg ( object_id ))  from  all_objects b  where  b.owner = a.username) data from  all_users a) a;

  执行结果:

             5390   recursive calls
               
0   db block gets
           
98662   consistent gets

 

  总结:

     通过上面的测试发现,TOM的《Oracle高效设计》里谈到的标量子查询的性能要由于关联查询,在旧版本的中可能是可以的,在10gR2中是不成立的

转载于:https://www.cnblogs.com/zping/archive/2008/10/19/1314685.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值