通过索引读取表的速度和通过索引物理顺序读取表数据的速度对比

情景:

       1.两个库,在库A中处理逻辑,dblink 读取库B总的大表数据(4亿条,有分区和索引)。

       2.要处理的数据,大概能占到表数据的三分之一到三分之二。

      3.通过索引查询,条件处理的话,这边配置是(8核,16G内存),dblink并行查询没什么作用。

       4.测试代码,如下:

       --TEST 1 走索引查询
declare 
  CURSOR monitor_out_cursor
  is
    select * from cd_table_1 where rownum<2000
  ;
  cur_monitor_out_cursor cd_table_1 %rowtype;
  t1 number := 0;
  t2 number := 0;
  t3 number := 0;
  type t_atxnhis is table of cd_table_2%rowtype index by binary_integer;
  tmp_record t_atxnhis;
  i number := 0; --卡号数
  j number := 0; --交易明细记录数
begin
  t1 := dbms_utility.get_time;
  open monitor_out_cursor;
  loop
       fetch monitor_out_cursor into cur_monitor_out_cursor;
             for tmp_record in(
                 select * from cd_table_2 a where a.name=cur_monitor_out_cursor.name
               )loop
                 j := j+1;
               end loop;
       exit when monitor_out_cursor %notfound;
       i := i + 1;
  end loop;
  t2 := dbms_utility.get_time;
  t3 := t2 - t1;
  dbms_output.put_line('cursor cost time is ' || t3 || ' 秒,total record num is ' || j || ' 条');
end;


cd_table_2  为dblink 大数据表。


--TEST 2 未加条件查询
declare 
  CURSOR monitor_out_cursor
  is
    select * from cd_table_2  
  ;
  cur_monitor_out_cursor cd_table_2%rowtype;
  t1 number := 0;
  t2 number := 0;
  t3 number := 0;
  i number := 0;
  j number := 0;
  cnt number := 920113;
begin
  t1 := dbms_utility.get_time;
  open monitor_out_cursor;
  loop
       fetch monitor_out_cursor into cur_monitor_out_cursor;
       exit when i>=cnt or monitor_out_cursor %notfound;
       i := i + 1;
  end loop;
  t2 := dbms_utility.get_time;
  t3 := t2 - t1;
  dbms_output.put_line('cursor cost time is ' || t3 || ' 秒,total record num is ' || i || ' 条');
end;

两个查询的查询速度比较:

      为了方便:只进行了920113条的测试。

     这个数据 920113 是要和 第一次通过索引读取到的数据的条数一致的。

      测试时间是这样的:

     通过走索引的查询时间是3个小时以上,没有测完,时间太长了。

     通过游标顺序查询读取的时间是:454.75 秒

     这个时间差距还是看的出来的。

    


1.这个其实主要测试了,索引的使用,检索数据的速度。

    还有就是游标物理的顺序读取数据的速度的差异。

2.显然数据读取的速度是很快的。这个应该就是取决于io 和 网络io 速度了吧。 ?


3.这个以后为了进行分布式的处理,取数据的时候,根据特定需求分发数据,读取数据速度很快的话,这样进行数据分发就OK了。





  

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值