10053事件

借助Oracle10053事件event,我们可以监控到CBOSQL进行成本计算和路径选择的过程和方法。

10053事件有两个级别:

Level 22级是1级的一个子集,它包含以下内容:

Column statistics

Single Access Paths

Join Costs

Table Joins Considered

Join Methods Considered (NL/MS/HA)

Level 1 1级比2级更详细,它包含2级的所有内容,在加如下内容:

Parameters used by the optimizer

Index statistics

启用10053事件

ALTER SESSION SET EVENTS='10053 trace name context forever, level 1';

ALTER SESSION SET EVENTS='10053 trace name context forever, level 2';

关闭10053事件:

ALTER SESSION SET EVENTS '10053 trace name context off';

说明:

1sqlplus中打开autotrace看到的执行计划实际上是用explain plan 命令得到的,explain plan 命令不会进行bind peeking。应该通过v$sql_plan查看SQL的真实的执行计划。

210053只对CBO有效,而且如果一个sql语句已经解析过,就不会产生新的trace信息。

310053事件产生的trace文件不能用tkprof格式化。

--------- 通过10053事件分析一个SQL执行计划的产生过程,需要贴出trace中的相关信息和必要的文字说明
---创建两个测试表
  1. SQL> create table t1 as select * from all_objects;

  2. Table created.
  3.  
  4. SQL> select count(*) from t1;

  5.   COUNT(*)
  6. ----------
  7.      68323

  8. SQL> create table t2 as select * from all_objects where rownum<=100;

  9. Table created.

  10. SQL> select count(*) from t2;

  11.   COUNT(*)
  12. ----------
  13.        100

  14. SQL>
----对T1、T2表进行分析、不生成直方图

  1. SQL> exec dbms_stats.gather_table_stats('SCOTT','T1',cascade=>true,estimate_percent=>null,method_opt=>'for all columns size 1');

  2. PL/SQL procedure successfully completed.

  3. SQL> exec dbms_stats.gather_table_stats('SCOTT','T2',cascade=>true,estimate_percent=>null,method_opt=>'for all columns size 1');

  4. PL/SQL procedure successfully completed.

  5. SQL>
----生成trace文件

  1. SQL> alter session set events '10053 trace name context forever ,level 1';

  2. Session altered.

  3. SQL> select count(*) from scott.t1,scott.t2 where t1.object_id=t2.object_id;

  4.   COUNT(*)
  5. ----------
  6.        100

  7. SQL>
  8. SQL> alter session set events '10053 trace name context off';

  9. Session altered.

  10. SQL>
  11. SQL> select value from v$diag_info where name like '%Default%';

  12. VALUE
  13. --------------------------------------------------------------------------------
  14. /u01/app/oracle/diag/rdbms/ora/ORA/trace/ORA_ora_12822.trc

  15. SQL>
-----查看trace文件

  1. [oracle@ds ~]$ more /u01/app/oracle/diag/rdbms/ora/ORA/trace/ORA_ora_12822.trc
  2. Trace file /u01/app/oracle/diag/rdbms/ora/ORA/trace/ORA_ora_12822.trc
  3. Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
  4. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  5. ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1
  6. ·············································································
  7. Peeked values of the binds in SQL statement
  8. *******************************************

  9. Final query after transformations:******* UNPARSED QUERY IS *******
  10. SELECT COUNT(*) "COUNT(*)" FROM "SCOTT"."T1" "T1","SCOTT"."T2" "T2" WHERE "T1"."OB
  11. JECT_ID"="T2"."OBJECT_ID"
  12. kkoqbc: optimizing query block SEL$1 (#0)
  13.         
  14.         :
  15.     call(in-use=1928, alloc=16344), compile(in-use=58824, alloc=62776), execution(
  16. in-use=3296, alloc=4032)

  17. kkoqbc-subheap (create addr=0x7f11c504fa10)
  18. ****************
  19. QUERY BLOCK TEXT
  20. ****************
  21. select count(*) from scott.t1,scott.t2 where t1.object_id=t2.object_id
  22. ---------------------
  23. QUERY BLOCK SIGNATURE
  24. ---------------------
  25. signature (optimizer): qb_name=SEL$1 nbfros=2 flg=0
  26.   fro(0): flg=0 objn=88661 hint_alias="T1"@"SEL$1"
  27.   fro(1): flg=0 objn=88662 hint_alias="T2"@"SEL$1"

  28. -----------------------------
  29. SYSTEM STATISTICS INFORMATION
  30. -----------------------------
  31.   Using NOWORKLOAD Stats
  32.   CPUSPEEDNW: 3074 millions instructions/sec (default is 100)
  33.   IOTFRSPEED: 4096 bytes per millisecond (default is 4096)
  34.   IOSEEKTIM: 10 milliseconds (default is 10)
  35.   MBRC: NO VALUE blocks (default is 8)

  36. ***************************************
  37. BASE STATISTICAL INFORMATION
  38. ***********************
  39. Table Stats::
  40.   Table: T2 Alias: T2
  41.     #Rows: 100 #Blks: 5 AvgRowLen: 89.00 ChainCnt: 0.00
  42.   Column (#4): OBJECT_ID(
  43.     AvgLen: 4 NDV: 100 Nulls: 0 Density: 0.010000 Min: 100 Max: 1495
  44. ***********************
  45. Table Stats::
  46.   Table: T1 Alias: T1
  47.     #Rows: 68323 #Blks: 1011 AvgRowLen: 98.00 ChainCnt: 0.00
  48.   Column (#4): OBJECT_ID(
  49.     AvgLen: 5 NDV: 68323 Nulls: 0 Density: 0.000015 Min: 100 Max: 88661
  50. Access path analysis for T1
  51. ***************************************
  52. SINGLE TABLE ACCESS PATH
  53.   Single Table Cardinality Estimation for T1[T1]
  54.   Table: T1 Alias: T1
  55.     Card: Original: 68323.000000 Rounded: 68323 Computed: 68323.00 Non Adjusted
  56. : 68323.00
  57.   Access Path: TableScan
  58.     Cost: 276.58 Resp: 276.58 Degree: 0
  59.       Cost_io: 276.00 Cost_cpu: 21547606
  60.       Resp_io: 276.00 Resp_cpu: 21547606
  61.   Best:: AccessPath: TableScan
  62.          Cost: 276.58 Degree: 1 Resp: 276.58 Card: 68323.00 Bytes: 0

  63. Access path analysis for T2
  64. ***************************************
  65. SINGLE TABLE ACCESS PATH
  66.   Single Table Cardinality Estimation for T2[T2]
  67.   Table: T2 Alias: T2
  68.     Card: Original: 100.000000 Rounded: 100 Computed: 100.00 Non Adjusted: 100.
  69. 00
  70.   Access Path: TableScan
  71.     Cost: 3.00 Resp: 3.00 Degree: 0
  72.       Cost_io: 3.00 Cost_cpu: 56607
  73.       Resp_io: 3.00 Resp_cpu: 56607
  74.   Best:: AccessPath: TableScan
  75.          Cost: 3.00 Degree: 1 Resp: 3.00 Card: 100.00 Bytes: 0

  76. ***************************************


  77. OPTIMIZER STATISTICS AND COMPUTATIONS
  78. ***************************************
  79. GENERAL PLANS
  80. ***************************************
  81. Considering cardinality-based initial join order.
  82. Permutations for Starting Table :0
  83. Join order[1]: T2[T2]#0 T1[T1]#1

  84. ***************
  85. Now joining: T1[T1]#1
  86. ***************
  87. NL Join
  88.   Outer table: Card: 100.00 Cost: 3.00 Resp: 3.00 Degree: 1 Bytes: 4
  89. Access path analysis for T1
  90.   Inner table: T1 Alias: T1
  91.   Access Path: TableScan
  92.     NL Join: Cost: 27444.41 Resp: 27444.41 Degree: 1
  93.       Cost_io: 27386.00 Cost_cpu: 2154817191
  94.       Resp_io: 27386.00 Resp_cpu: 2154817191

  95.   Best NL cost: 27444.41
  96.           resc: 27444.41 resc_io: 27386.00 resc_cpu: 2154817191
  97.           resp: 27444.41 resp_io: 27386.00 resc_cpu: 2154817191
  98. Join Card: 100.000000 = outer (100.000000) * inner (68323.000000) * sel (0.000015
  99. )
  100. Join Card - Rounded: 100 Computed: 100.00
  101.   Outer table: T2 Alias: T2
  102.     resc: 3.00 card 100.00 bytes: 4 deg: 1 resp: 3.00
  103.   Inner table: T1 Alias: T1
  104.     resc: 276.58 card: 68323.00 bytes: 5 deg: 1 resp: 276.58
  105.     using dmeth: 2 #groups: 1
  106.     SORT ressource Sort statistics
  107.       Sort width: 430 Area size: 352256 Max Area size: 75497472
  108.       Degree: 1
  109.       Blocks to Sort: 1 Row size: 15 Total Rows: 100
  110.       Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
  111.       Total IO sort cost: 0 Total CPU sort cost: 36918822
  112.       Total Temp space used: 0
  113.     SORT ressource Sort statistics
  114.       Sort width: 430 Area size: 352256 Max Area size: 75497472
  115.       Degree: 1
  116.       Blocks to Sort: 134 Row size: 16 Total Rows: 68323
  117.       Initial runs: 2 Merge passes: 1 IO Cost / pass: 74
  118.       Total IO sort cost: 208 Total CPU sort cost: 89625937
  119.       Total Temp space used: 1663000
  120.   SM join: Resc: 491.02 Resp: 491.02 [multiMatchCost=0.00]
  121. SM Join
  122.   SM cost: 491.02
  123.      resc: 491.02 resc_io: 487.00 resc_cpu: 148148972
  124.      resp: 491.02 resp_io: 487.00 resp_cpu: 148148972
  125.   Outer table: T2 Alias: T2
  126.     resc: 3.00 card 100.00 bytes: 4 deg: 1 resp: 3.00
  127.   Inner table: T1 Alias: T1
  128.     resc: 276.58 card: 68323.00 bytes: 5 deg: 1 resp: 276.58
  129.     using dmeth: 2 #groups: 1
  130.     Cost per ptn: 0.20 #ptns: 1
  131.     hash_area: 124 (max=18432) buildfrag: 1 probefrag: 142 ppasses: 1
  132.   Hash join: Resc: 279.79 Resp: 279.79 [multiMatchCost=0.00]
  133. HA Join
  134.   HA cost: 279.79
  135.      resc: 279.79 resc_io: 279.00 resc_cpu: 29051513
  136.      resp: 279.79 resp_io: 279.00 resp_cpu: 29051513
  137. Best:: JoinMethod: Hash
  138.        Cost: 279.79 Degree: 1 Resp: 279.79 Card: 100.00 Bytes: 9
  139. ***********************
  140. Best so far: Table#: 0 cost: 3.0015 card: 100.0000 bytes: 400
  141.               Table#: 1 cost: 279.7875 card: 100.0000 bytes: 900
  142. ***********************
  143. Join order[2]: T1[T1]#1 T2[T2]#0

  144. ***************
  145. Now joining: T2[T2]#0
  146. ***************
  147. NL Join
  148.   Outer table: Card: 68323.00 Cost: 276.58 Resp: 276.58 Degree: 1 Bytes: 5
  149. Access path analysis for T2
  150.   Inner table: T2 Alias: T2
  151.   Access Path: TableScan
  152.     NL Join: Cost: 92903.43 Resp: 92903.43 Degree: 1
  153.       Cost_io: 92798.00 Cost_cpu: 3889121331
  154.       Resp_io: 92798.00 Resp_cpu: 3889121331

  155.   Best NL cost: 92903.43
  156.           resc: 92903.43 resc_io: 92798.00 resc_cpu: 3889121331
  157.           resp: 92903.43 resp_io: 92798.00 resc_cpu: 3889121331
  158. Join Card: 100.000000 = outer (68323.000000) * inner (100.000000) * sel (0.000015
  159. )
  160. Join Card - Rounded: 100 Computed: 100.00
  161.   Outer table: T1 Alias: T1
  162.     resc: 276.58 card 68323.00 bytes: 5 deg: 1 resp: 276.58
  163.   Inner table: T2 Alias: T2
  164.     resc: 3.00 card: 100.00 bytes: 4 deg: 1 resp: 3.00
  165.     using dmeth: 2 #groups: 1
  166.     SORT ressource Sort statistics
  167.       Sort width: 430 Area size: 352256 Max Area size: 75497472
  168.       Degree: 1
  169.       Blocks to Sort: 134 Row size: 16 Total Rows: 68323
  170.       Initial runs: 2 Merge passes: 1 IO Cost / pass: 74
  171.       Total IO sort cost: 208 Total CPU sort cost: 89625937
  172.       Total Temp space used: 1663000
  173.     SORT ressource Sort statistics
  174.       Sort width: 430 Area size: 352256 Max Area size: 75497472
  175.       Degree: 1
  176.       Blocks to Sort: 1 Row size: 15 Total Rows: 100
  177.       Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
  178.       Total IO sort cost: 0 Total CPU sort cost: 36918822
  179.       Total Temp space used: 0
  180.   SM join: Resc: 491.02 Resp: 491.02 [multiMatchCost=0.00]
  181. SM Join
  182.   SM cost: 491.02
  183.      resc: 491.02 resc_io: 487.00 resc_cpu: 148148972
  184.      resp: 491.02 resp_io: 487.00 resp_cpu: 148148972
  185.   Outer table: T1 Alias: T1
  186.     resc: 276.58 card 68323.00 bytes: 5 deg: 1 resp: 276.58
  187.   Inner table: T2 Alias: T2
  188.     resc: 3.00 card: 100.00 bytes: 4 deg: 1 resp: 3.00
  189.     using dmeth: 2 #groups: 1
  190.     Cost per ptn: 56.31 #ptns: 1
  191.     hash_area: 124 (max=18432) buildfrag: 142 probefrag: 1 ppasses: 1
  192.   Hash join: Resc: 335.90 Resp: 335.90 [multiMatchCost=0.00]
  193.   Outer table: T2 Alias: T2
  194.     resc: 3.00 card 100.00 bytes: 4 deg: 1 resp: 3.00
  195.   Inner table: T1 Alias: T1
  196.     resc: 276.58 card: 68323.00 bytes: 5 deg: 1 resp: 276.58
  197.     using dmeth: 2 #groups: 1
  198.     Cost per ptn: 0.20 #ptns: 1
  199.     hash_area: 124 (max=18432) buildfrag: 1 probefrag: 142 ppasses: 1
  200.   Hash join: Resc: 279.79 Resp: 279.79 [multiMatchCost=0.00]
  201. HA Join
  202.   HA cost: 279.79 swapped
  203.      resc: 279.79 resc_io: 279.00 resc_cpu: 29051513
  204.      resp: 279.79 resp_io: 279.00 resp_cpu: 29051513
  205. Join order aborted: cost > best plan cost
  206. ***********************
  207. (newjo-stop-1) k:0, spcnt:0, perm:2, maxperm:2000

  208. *********************************
  209. Number of join permutations tried: 2
  210. *********************************
  211. Consider using bloom filter between T2[T2] and T1[T1] with ??
  212. kkoBloomFilter: join ndv:0 reduction:1.000000 (limit:0.500000) rejected because n
  213. o single-tables predicates
  214. Enumerating distribution method (advanced)
  215. --- Distribution method for
  216. join between T2[T2](serial) and T1[T1](serial); jm = 1; right side access path = T
  217. ableScan
  218. ---- serial Hash-Join -> NONE

  219. (newjo-save) [0 1 ]
  220. Trying or-Expansion on query block SEL$1 (#0)
  221. Transfer Optimizer annotations for query block SEL$1 (#0)
  222. id=0 frofkksm[i] (sort-merge/hash) predicate="T1"."OBJECT_ID"="T2"."OBJECT_ID"
  223. id=0 frosand (sort-merge/hash) predicate="T1"."OBJECT_ID"="T2"."OBJECT_ID"
  224. Final cost for query block SEL$1 (#0) - All Rows Plan:
  225.   Best join order: 1
  226.   Cost: 279.7875 Degree: 1 Card: 100.0000 Bytes: 900
  227.   Resc: 279.7875 Resc_io: 279.0000 Resc_cpu: 29051513
  228.   Resp: 279.7875 Resp_io: 279.0000 Resc_cpu: 29051513
  229. kkoqbc-subheap (delete addr=0x7f11c504fa10, in-use=36144, alloc=49272)
  230. kkoqbc-end:
  231.         :
  232.     call(in-use=10704, alloc=82128), compile(in-use=62376, alloc=62776), execution
  233. (in-use=3296, alloc=4032)

  234. kkoqbc: finish optimizing query block SEL$1 (#0)
  235. apadrv-end
  236.           :
  237.     call(in-use=10704, alloc=82128), compile(in-use=63376, alloc=66920), execution
  238. (in-use=3296, alloc=4032)


  239. Starting SQL statement dump

  240. user_id=0 user_name=SYS module=sqlplus@ds (TNS V1-V3) action=
  241. sql_id=aqkx0jysz4fr9 plan_hash_value=-20910549 problem_type=3
  242. ----- Current SQL Statement for this session (sql_id=aqkx0jysz4fr9) -----
  243. select count(*) from scott.t1,scott.t2 where t1.object_id=t2.object_id
  244. sql_text_length=71
  245. sql=select count(*) from scott.t1,scott.t2 where t1.object_id=t2.object_id
  246. ----- Explain Plan Dump -----
  247. ----- Plan Table -----
  248.  
  249. ============
  250. Plan Table
  251. ============
  252. ---------------------------------------+-----------------------------------+
  253. | Id | Operation | Name | Rows | Bytes | Cost | Time |
  254. ---------------------------------------+-----------------------------------+
  255. | 0 | SELECT STATEMENT | | | | 280 | |
  256. | 1 | SORT AGGREGATE | | 1 | 9 | | |
  257. | 2 | HASH JOIN | | 100 | 900 | 280 | 00:00:04 |
  258. | 3 | TABLE ACCESS FULL | T2 | 100 | 400 | 3 | 00:00:01 |
  259. | 4 | TABLE ACCESS FULL | T1 | 67K | 334K | 277 | 00:00:04 |
  260. ---------------------------------------+-----------------------------------+
  261. Predicate Information:
  262. ----------------------
  263. 2 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")
  264.  
  265. Content of other_xml column
  266. ===========================
  267.   db_version : 11.2.0.4
  268.   parse_schema : SYS
  269.   plan_hash : 4274056747
  270. --More--(60%)






来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31399171/viewspace-2131066/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31399171/viewspace-2131066/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值