Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1300760
  • 博文数量: 127
  • 博客积分: 2286
  • 博客等级: 大尉
  • 技术积分: 1943
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-10 10:37
文章分类

全部博文(127)

文章存档

2018年(1)

2015年(2)

2014年(1)

2013年(30)

2012年(88)

2011年(5)

分类: Oracle

2013-04-23 13:07:16

概述

考虑到cursor_sharing=similar带来的诸多问题,Oracle在11g中废弃改选项(11.1.06和11.2.02以上),并再12c中彻底删除

废弃原因child cursor下面2种情况,只有文字变量完全一样才共享child cursor尽管执行计划一样

1 谓词字段上有histogram

2 谓词此段无histogram,但用的非等值查询(>,<=,!=, between)

测试验证 1:有histogram


点击(此处)折叠或打开

  1. SQL> show parameter cursor_sharing
  2. NAME TYPE VALUE
  3. --------------- -------- ---------
  4. cursor_sharing string SIMILAR


  5. SQL> begin
  6.      for r1 in 0..200 loop
  7.         for r2 in 150..200 loop
  8.           execute immediate 'select count(*) from hwz where id='||r1||' and name='''||r2||'''';
  9.         end loop;
  10.      end loop;
  11. end;
  12. /
  13. Elapsed: 00:00:22.16
  14. SQL> /

  15. Elapsed: 00:00:01.72

  16. select SQL_ID,version_count,SQL_TEXT
  17. from v$sqlarea where sql_id='btyb5w7xzrpzf'
  18. SQL_ID VERSION_COUNT SQL_TEXT
  19. ------------- ------------- ----------------------------------------
  20. btyb5w7xzrpzf 13556 select count(*) from hwz where id=:"SYS_
  21.                             B_0" and name=:"SYS_B_1"


  22. SQL> l
  23.   1 SELECT IS_SHAREABLe,count(*)
  24.   2 from v$sql where sql_id ='btyb5w7xzrpzf'
  25.   3* group by IS_SHAREABLe
  26. SQL> /

  27. 14-APR-13 Shared Pool Sizing Advice Report

  28. I COUNT(*)
  29. - ----------
  30. Y 10251

  31. 1 row selected.
生成了过万的child cursor,内存够用还是很快的

点击(此处)折叠或打开

  1. begin
  2.      for r1 in 0..200 loop
  3.         for r2 in 100..200 loop
  4.           execute immediate 'select count(*) from hwz where id='||r1||' and name='''||r2||'''';
  5.         end loop;
  6.      end loop;
  7. end;
  8. /
  9. ORA-01013: user requested cancel of current operation
  10. ORA-06512: at line 4
  11. Elapsed: 00:45:20.87
45分钟没执行完我中断了

点击(此处)折叠或打开

  1. SQL> select sid,event,p1,p2,wait_time from v$session where wait_time>0;

  2.  SID EVENT P1 P2 WAIT_TIME
  3. ---- ------------------------------ ---------- ---------- ----------
  4.    1 library cache: mutex X 4227586030 1.5032E+11 239


  5. SELECT IS_SHAREABLe,count(*)
  6. from v$sql where sql_id ='btyb5w7xzrpzf'
  7. group by IS_SHAREABLe;
  8. 14-APR-13
  9. I COUNT(*)
  10. - ----------
  11. Y 11764
  12. N 1703

  13. I COUNT(*)
  14. - ----------
  15. Y 10194
  16. N 3283

  17. I COUNT(*)
  18. - ----------
  19. Y 8012
  20. N 5474

  21. I COUNT(*)
  22. - ----------
  23. Y 236
  24. N 11819
library cache: mutex X正是硬解析得标识,在不停的添加child cursor
Child cursor太多,过1万的时候,内存不够,ege out了

无histogram的测试


点击(此处)折叠或打开

  1. exec dbms_stats.DELETE_TABLE_STATS(user,'HWZ');    
  2. exec dbms_stats.gather_table_stats('ORACLE_OCM','HWZ');

  3. begin
  4.      for r1 in 0..200 loop
  5.         for r2 in 100..200 loop
  6.           execute immediate 'select count(*) from hwz where id='||r1||' and name='''||r2||'''';
  7.         end loop;
  8.      end loop;
  9. end;
  10. /
  11. Elapsed: 00:00:01.79


  12. SELECT IS_SHAREABLe,count(*)
  13. from v$sql where sql_id ='btyb5w7xzrpzf'
  14. group by IS_SHAREABLe;

  15. I COUNT(*)
  16. - ----------
  17. Y 1

非等值的查询


点击(此处)折叠或打开

  1. begin
  2.      for r1 in 0..200 loop
  3.         for r2 in 100..200 loop
  4.           execute immediate 'select count(*) from hwz where id>'||r1||' and name like '''||r2||'''';
  5.         end loop;
  6.      end loop;
  7. end;
  8. /
  9. 时间太长,我中断了...

  10. SELECT IS_SHAREABLe,count(*)
  11. from v$sql where sql_id ='5psxu5unhhm2j'
  12. group by IS_SHAREABLe;

  13. I COUNT(*)
  14. - ----------
  15. Y 4768
  16. N 8400


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

kerlion2013-05-06 15:47:09

建立child cursor的原因是HASH_MATCH_FAILED