Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2765865
  • 博文数量: 389
  • 博客积分: 4177
  • 博客等级: 上校
  • 技术积分: 4773
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-16 23:29
文章分类

全部博文(389)

分类: Oracle

2014-04-14 17:27:02

                       Timesten(TT)和ORACLE执行效率测试

    TT是一个内存数据库,在某些方面执行要比oracle快,因为代码路径和优化器
都没有oracle那么复杂,即使把oracle的数据全部cache到sga中也没有TT快.详细
的讨论见我之前的blog中的讨论,因此在合适的时机用好TT很重要.

  现在我们来测这两者倒底有多大的区别.


TT的版本:11.2.2.5.0 (perm 4G,非持久提交)
oracle版本:11.1.0.7(归档模式,16G SGA)
OS: rhel 5.5
 
在oracle中和TT建如下表:

create table t1
(a number(38) ,
 b varchar2(100),
 c varchar2(100),
 d number(38),
 primary key (a))

连接的方法TT使用的TTisql,oracle用的是sqlplus(beq),这样减少了网络开销,使用
工具本身的计时方法


首先看insert
SQL> declare
  2   i int;
  3  begin
  4  for i in 1..5000000
  5    loop
  6   insert into t1 values(i,'asfsfsf','asdfaaaaaaaaaaaaaaaa',i+100);
  7  end loop;
  8  end;
  9  /

PL/SQL procedure successfully completed.

Elapsed: 00:12:41.01  --oracle数据库执行时间12:41秒

 

Command> declare
       >  i int;
       > begin
       > for i in 1..5000000
       >   loop
       >  insert into t1 values(i,'asfsfsf','asdfaaaaaaaaaaaaaaaa',i+100);
       > end loop;
       > end;
       > /

PL/SQL procedure successfully completed.

Execution time (SQLExecute) = 1133.525045 seconds.


TT执行的时间花费将近到20分钟,在insert语句的情况下,TT比oracle还慢,而且TT还使用
了非持久化提交。如果并发一高的话,可能oracle的log file sync等待越来越严重.

 


select执行效率

SQL> exec dbms_stats.gather_table_stats('SYSTEM','T1');

PL/SQL procedure successfully completed.

SQL> declare
  2   i int;
  3   j varchar2(200);
  4  begin
  5  for i in 1..5000000
  6    loop
  7   select b into j from t1 where a=i;
  8  end loop;
  9  end;
 10  /

PL/SQL procedure successfully completed.

Elapsed: 00:03:58.34   --执行500万个查询,oracle花费时间03:58


Command> call TTOptEstimateStats('T1',0,'100 PERCENT');  ##100%取样
Command> declare
       >  i int;
       >  j varchar2(200);
       > begin
       > for i in 1..5000000
       >   loop
       >  select b into j from t1 where a=i;
       > end loop;
       > end;
       > /

PL/SQL procedure successfully completed.

Execution time (SQLExecute) = 28.786624 seconds.  --TT花费时间 28.7秒

通过一个简单的select语句,我们发现TT在执行简单的select 语句的比oracle速度要很多.
这个时候TT对简单的sql执行优势体现得非常明显.简单的主健查找,如果在TT中的
主健使用hash索引的话,TT可能会更快.


复杂的SQL测试

同时我们也发现对稍微复杂一点的sql,TT执行的速度就慢得太多了,这主要得益于
oracle强大的优化器.


SQL> declare
  2   i int;
  3   j int;
  4  begin
  5  for i in 1..10
  6    loop
  7   select count(*) into j
  8  from t1,t1 temp1,t1 temp2
  9  where t1.a=i
 10  and temp1.b=temp2.b
 11  and temp1.a=t1.a
 12  and temp1.b<>'adf';
 13  end loop;
 14  end;
 15  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:06.33            --oracle执行时间6.33秒


Command> declare
       >  i int;
       >  j int;
       > begin
       > for i in 1..10
       >   loop
       >  select count(*) into j
       > from t1,t1 temp1,t1 temp2
       > where t1.a=i
       > and temp1.b=temp2.b
       > and temp1.a=t1.a
       > and temp1.b<>'adf';
       > end loop;
       > end;
       > /

PL/SQL procedure successfully completed.

Execution time (SQLExecute) = 31.921144 seconds.  --TT执行时间31.9秒


可以看到对于复杂的SQL,TT慢的惨不忍睹.

阅读(5983) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~