你好,游客 登录 注册 搜索
背景:
阅读新闻

浅谈Oracle绑定变量

[日期:2012-06-16] 来源:Linux社区  作者:ylw6006 [字体:大 中 小]

3:使用绑定变量情况下,进行sql trace分析,执行1万次,只需要硬解析5次,其中包含递归解析,解析时间和cpu时间基本忽略不计

  1. SQL> alter session set tracefile_identifier='HR02';  
  2. Session altered.  
  3.  
  4. SQL> alter session set sql_trace=TRUE;  
  5. Session altered.  
  6.  
  7. SQL> begin  
  8.   2  for i in 1..10000  
  9.   3  loop  
  10.   4  execute immediate 'select * from t1 where object_id=:i' using i;  
  11.   5  end loop;  
  12.   6  end;  
  13. PL/SQL procedure successfully completed.  
  14.  
  15. SQL> alter session set sql_trace=FALSE;  
  16. Session altered.  
  17.  
  18. OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS  
  19.  
  20. call     count       cpu    elapsed       disk      query    current        rows  
  21. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
  22. Parse        5      0.00       0.00          0          0          0           0  
  23. Execute  10004      0.10       0.09          0          0          0           0  
  24. Fetch       10      0.00       0.01          0         29          0           7  
  25. ------- ------  -------- ---------- ---------- ---------- ----------  ----------  
  26. total    10019      0.10       0.10          0         29          0           7  
  27.  
  28. Misses in library cache during parse: 2  
  29. Misses in library cache during execute: 1  
  30.  
  31.     4  user  SQL statements in session.  
  32.     4  internal SQL statements in session.  
  33.     8  SQL statements in session.  
  34.     0  statements EXPLAINed in this session.  
  35. ********************************************************************************  
  36. Trace file: dg53_ora_24818_HR02.trc  
  37. Trace file compatibility: 10.01.00  
  38. Sort options: default  
  39.  
  40.        0  session in tracefile.  
  41.        4  user  SQL statements in trace file.  
  42.        4  internal SQL statements in trace file.  
  43.        8  SQL statements in trace file.  
  44.        8  unique SQL statements in trace file.  
  45.    10078  lines in trace file.  
  46.       91  elapsed seconds in trace file. 

二:使用绑定变量有如此好的效果,那么这是不是百利无一害的技术手段呢?下面在OLAP环境下测试
1:创建测试数据,olap环境下分区的技术非常普遍,且数据量非常大

  1. [root@dg53 ~]# su - Oracle  
  2. [oracle@dg53 ~]$ sqlplus /nolog  
  3. SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jun 15 09:05:35 2012  
  4. Copyright (c) 1982, 2005, Oracle.  All rights reserved.  
  5.  
  6. SQL> conn /as sysdba  
  7. Connected.  
  8. SQL> create tablespace data01;  
  9. Tablespace created.  
  10.  
  11. SQL> create tablespace data02;  
  12. Tablespace created.  
  13.  
  14. SQL> create tablespace data03;  
  15. Tablespace created.  
  16.  
  17. SQL> create tablespace data04;  
  18. Tablespace created.  
  19.  
  20. SQL> conn hr/hr  
  21. Connected.  
  22.  
  23. SQL> create table t2 (object_id number,object_name varchar2(200))  
  24.   2  partition by range(object_id)  
  25.   3  (partition p1 values less than(5000) tablespace data01,  
  26.   4   partition p2 values less than(10000) tablespace data02,  
  27.   5   partition p3 values less than(15000) tablespace data03,  
  28.   6*  partition pm values less than(maxvalue) tablespace data04)  
  29. Table created.  
  30.  
  31. SQL> begin  
  32.   2  for i in 1..300  
  33.   3  loop  
  34.   4  insert into t2 select object_id,object_name from dba_objects;  
  35.   5  end loop;  
  36.   6  end;  
  37. PL/SQL procedure successfully completed.  
  38.  
  39. SQL> commit;  
  40. Commit complete.  
  41.  
  42. SQL> create index i_t_id on t2(object_id) local  
  43.   2  (partition p1 tablespace data01,  
  44.   3   partition p2 tablespace data02,  
  45.   4   partition p3 tablespace data03,  
  46.   5   partition pm tablespace data04);  
  47. Index created.  
  48.  
  49. SQL> exec dbms_stats.gather_table_stats('HR','T2',CASCADE=>TRUE);  
  50. PL/SQL procedure successfully completed.  
  51.  
  52. SQL> select count(*) from t2 partition(p1);  
  53.  
  54.   COUNT(*)  
  55. ----------  
  56.    1474800  
  57.  
  58. SQL> select count(*) from t2 partition(p2);  
  59.  
  60.   COUNT(*)  
  61. ----------  
  62.    1398900  
  63.  
  64. SQL> select count(*) from t2 partition(p3);  
  65.  
  66.   COUNT(*)  
  67. ----------  
  68.    1491900  
  69.  
  70. SQL> select count(*) from t2 partition(pm);  
  71.  
  72.   COUNT(*)  
  73. ----------  
  74.   10752600 
linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款