3:使用绑定变量情况下,进行sql trace分析,执行1万次,只需要硬解析5次,其中包含递归解析,解析时间和cpu时间基本忽略不计
- SQL> alter session set tracefile_identifier='HR02';
- Session altered.
- SQL> alter session set sql_trace=TRUE;
- Session altered.
- SQL> begin
- 2 for i in 1..10000
- 3 loop
- 4 execute immediate 'select * from t1 where object_id=:i' using i;
- 5 end loop;
- 6 end;
- PL/SQL procedure successfully completed.
- SQL> alter session set sql_trace=FALSE;
- Session altered.
- OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
- call count cpu elapsed disk query current rows
- ------- ------ -------- ---------- ---------- ---------- ---------- ----------
- Parse 5 0.00 0.00 0 0 0 0
- Execute 10004 0.10 0.09 0 0 0 0
- Fetch 10 0.00 0.01 0 29 0 7
- ------- ------ -------- ---------- ---------- ---------- ---------- ----------
- total 10019 0.10 0.10 0 29 0 7
- Misses in library cache during parse: 2
- Misses in library cache during execute: 1
- 4 user SQL statements in session.
- 4 internal SQL statements in session.
- 8 SQL statements in session.
- 0 statements EXPLAINed in this session.
- ********************************************************************************
- Trace file: dg53_ora_24818_HR02.trc
- Trace file compatibility: 10.01.00
- Sort options: default
- 0 session in tracefile.
- 4 user SQL statements in trace file.
- 4 internal SQL statements in trace file.
- 8 SQL statements in trace file.
- 8 unique SQL statements in trace file.
- 10078 lines in trace file.
- 91 elapsed seconds in trace file.
二:使用绑定变量有如此好的效果,那么这是不是百利无一害的技术手段呢?下面在OLAP环境下测试
1:创建测试数据,olap环境下分区的技术非常普遍,且数据量非常大
- [root@dg53 ~]# su - Oracle
- [oracle@dg53 ~]$ sqlplus /nolog
- SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jun 15 09:05:35 2012
- Copyright (c) 1982, 2005, Oracle. All rights reserved.
- SQL> conn /as sysdba
- Connected.
- SQL> create tablespace data01;
- Tablespace created.
- SQL> create tablespace data02;
- Tablespace created.
- SQL> create tablespace data03;
- Tablespace created.
- SQL> create tablespace data04;
- Tablespace created.
- SQL> conn hr/hr
- Connected.
- SQL> create table t2 (object_id number,object_name varchar2(200))
- 2 partition by range(object_id)
- 3 (partition p1 values less than(5000) tablespace data01,
- 4 partition p2 values less than(10000) tablespace data02,
- 5 partition p3 values less than(15000) tablespace data03,
- 6* partition pm values less than(maxvalue) tablespace data04)
- Table created.
- SQL> begin
- 2 for i in 1..300
- 3 loop
- 4 insert into t2 select object_id,object_name from dba_objects;
- 5 end loop;
- 6 end;
- PL/SQL procedure successfully completed.
- SQL> commit;
- Commit complete.
- SQL> create index i_t_id on t2(object_id) local
- 2 (partition p1 tablespace data01,
- 3 partition p2 tablespace data02,
- 4 partition p3 tablespace data03,
- 5 partition pm tablespace data04);
- Index created.
- SQL> exec dbms_stats.gather_table_stats('HR','T2',CASCADE=>TRUE);
- PL/SQL procedure successfully completed.
- SQL> select count(*) from t2 partition(p1);
- COUNT(*)
- ----------
- 1474800
- SQL> select count(*) from t2 partition(p2);
- COUNT(*)
- ----------
- 1398900
- SQL> select count(*) from t2 partition(p3);
- COUNT(*)
- ----------
- 1491900
- SQL> select count(*) from t2 partition(pm);
- COUNT(*)
- ----------
- 10752600
