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

Oracle 10g 10053事件

[日期:2012-02-13] 来源:Linux社区  作者:rulev5 [字体:大 中 小]
继续讨论10053事件的trace文件。    接下来部分展示了CBO计算的每个对象单独访问的代价。CBO要计算出每个对象单独访问时的代价,通过比较所有的数据访问的代价
通过比较所有的数据访问的代价,选择出代价最小的一种访问方式。

SINGLE TABLE ACCESS PATH
  -----------------------------------------
  BEGIN Single Table Cardinality Estimation
  -----------------------------------------
  Table:  T  Alias: T
    Card: Original: 50741  Rounded: 94  Computed: 94.04  Non Adjusted: 94.04
  -----------------------------------------
  END   Single Table Cardinality Estimation
  -----------------------------------------
  Access Path: TableScan
    Cost:  23.71  Resp: 23.71  Degree: 0
      Cost_io: 23.00  Cost_cpu: 10703672
      Resp_io: 23.00  Resp_cpu: 10703672
  Access Path: index (index (FFS))
    Index: IND_T
    resc_io: 32.00  resc_cpu: 9423571
    ix_sel: 0.0000e+00  ix_sel_with_filters: 1
  Access Path: index (FFS)
    Cost:  32.63  Resp: 32.63  Degree: 1
      Cost_io: 32.00  Cost_cpu: 9423571
      Resp_io: 32.00  Resp_cpu: 9423571
  Access Path: index (IndexOnly)
    Index: IND_T
    resc_io: 2.00  resc_cpu: 33243
    ix_sel: 0.0018533  ix_sel_with_filters: 0.0018533
    Cost: 2.00  Resp: 2.00  Degree: 1
  Best:: AccessPath: IndexRange  Index: IND_T
         Cost: 2.00  Degree: 1  Resp: 2.00  Card: 94.04  Bytes: 0

    这里里面的内容比较多,有两个指标对于我们的分析执行计划比较重要:
    Card:Original:50741
    原纪录数,也就是操作数据源的数据纪录数,在这里就是表的实际纪录50741
    Card:Rounded:96
    输出的纪录数,CBO计算出通过条件过滤,预计得到的纪录数。我们知道T安装条件小于100的纪录数是99条,这里估算出是96条,比较接近实际值。
    通过这一部分的信息我们看到,对于T表,CBO人为可能使用下面几种方式来访问数据。
全表扫描
  Access Path: TableScan
    Cost:  23.71  Resp: 23.71  Degree: 0
      Cost_io: 23.00  Cost_cpu: 10703672
      Resp_io: 23.00  Resp_cpu: 10703672

索引快速扫描
  Access Path: index (index (FFS)) ----Index fast full scan
 
单独访问索引:
  Access Path: index (IndexOnly)
 
    因为在结果集里面是T1表的信息,所以对于T表,只需要访问索引做关联条件查询,不需要访问表,所以单独访问索引也是可行的。
    
    CBO计算出三种方式产生的代价分别是:
    TableScan:            23.71
    index (FFS)            32.00
    index (IndexOnly)    2.00
    
    很显然,单独访问索引的方式是代价最低的,所以CBO得出的结论,对于T表上的查询,选择使用单独访问索引的方式。
***************************************
SINGLE TABLE ACCESS PATH
  -----------------------------------------
  BEGIN Single Table Cardinality Estimation
  -----------------------------------------
  Table: T1  Alias: T1
    Card: Original: 9999  Rounded: 99  Computed: 99.01  Non Adjusted: 99.01
  -----------------------------------------
  END   Single Table Cardinality Estimation
  -----------------------------------------
  Access Path: TableScan
    Cost:  6.14  Resp: 6.14  Degree: 0
      Cost_io: 6.00  Cost_cpu: 2122844
      Resp_io: 6.00  Resp_cpu: 2122844
  Access Path: index (RangeScan)
    Index: IND_T1
    resc_io: 3.00  resc_cpu: 58364
    ix_sel: 0.009902  ix_sel_with_filters: 0.009902
    Cost: 3.00  Resp: 3.00  Degree: 1
  Best:: AccessPath: IndexRange  Index: IND_T1
         Cost: 3.00  Degree: 1  Resp: 3.00  Card: 99.01  Bytes: 0
***************************************
    以上是T1表访问方式的扫描,CBO认为T1表的访问方式有两种:
  Access Path: TableScan
  Access Path: index (RangeScan)
    这两种方式的代价分别是:
TableScan 6.14
RangeScan 3.00
    最终CBO计算了买个表单独进行数据访问代价最小的方式,为下一步关系查询提供了代价的计算的数据依据。
    下面的部分CBO会列出T,T1表所有的关联方式,并计算出每一种关联方式的代价,最终选择代价最小的关联方式作为sql的执行计划,这里有六种情况:
    
        T关联T1
    ENSTED LOOPS JOIN(NL Join)
    SORT MERGE JOIN(SM Join)
    HASH JOIN(HA Join)
    
        T1关联T
    ENSTED LOOPS JOIN(NL Join)
    SORT MERGE JOIN(SM Join)
    HASH JOIN(HA Join)

以下为这一部分的trace信息:


第一部分 T关联T1
[sql]
  1. ***************************************  
  2. OPTIMIZER STATISTICS AND COMPUTATIONS  
  3. ***************************************  
  4. GENERAL PLANS  
  5. ***************************************  
  6. Considering cardinality-based initial join order.  
  7. Permutations for Starting Table :0  
  8. ***********************  
  9. Join order[1]:   T[T]#0  T1[T1]#1  
  10. ***************  
  11. Now joining: T1[T1]#1  
  12. ***************  
  13. NL Join  
  14.   Outer table: Card: 82.03  Cost: 2.00  Resp: 2.00  Degree: 1  Bytes: 4  
  15.   Inner table: T1  Alias: T1  
  16.   Access Path: TableScan  
  17.     NL Join:  Cost: 392.60  Resp: 392.60  Degree: 1  
  18.       Cost_io: 381.00  Cost_cpu: 174104090  
  19.       Resp_io: 381.00  Resp_cpu: 174104090  
  20. kkofmx: index filter:"T1"."X"<100 AND "T"."X"<100  
  21.   Access Path: index (AllEqJoinGuess)  
  22.     Index: IND_T1  
  23.     resc_io: 2.00  resc_cpu: 15463  
  24.     ix_sel: 1.0001e-04  ix_sel_with_filters: 9.9030e-07  
  25.     NL Join (ordered): Cost: 100.24  Resp: 100.24  Degree: 1  
  26.       Cost_io: 100.19  Cost_cpu: 823013  
  27.       Resp_io: 100.19  Resp_cpu: 823013  
  28.   Best NL cost: 100.24                                                  ------------>ENSTED LOOPS JOIN 方式最好的代价是100.24   
  29.           resc: 100.24 resc_io: 100.19 resc_cpu: 823013  
  30.           resp: 100.24 resp_io: 100.19 resp_cpu: 823013  
  31. Join Card:  81.22 = outer (82.03) * inner (99.01) * sel (0.01)  
  32. Join Card - Rounded: 81 Computed: 81.22  
  33. SM Join  
  34.   Outer table:  
  35.     resc: 2.00  card 82.03  bytes: 4  deg: 1  resp: 2.00  
  36.   Inner table: T1  Alias: T1  
  37.     resc: 3.00  card: 99.01  bytes: 6  deg: 1  resp: 3.00  
  38.     using dmeth: 2  #groups: 1  
  39.     SORT resource      Sort statistics  
  40.       Sort width:        1435 Area size:     1048576 Max Area size:   251238400  
  41.       Degree:               1  
  42.       Blocks to Sort:       1 Row size:           17 Total Rows:             99  
  43.       Initial runs:         1 Merge passes:        0 IO Cost / pass:          0  
  44.       Total IO sort cost: 0      Total CPU sort cost: 15041951  
  45.       Total Temp space used: 0  
  46.   SM join: Resc: 6.01  Resp: 6.01  [multiMatchCost=0.00]  
  47.   SM cost: 6.01                                                        ------------>SORT MERGE JOIN(SM Join) 方式最好的代价是6.01   
  48.      resc: 6.01 resc_io: 5.00 resc_cpu: 15131158  
  49.      resp: 6.01 resp_io: 5.00 resp_cpu: 15131158  
  50. HA Join  
  51.   Outer table:  
  52.     resc: 2.00  card 82.03  bytes: 4  deg: 1  resp: 2.00  
  53.   Inner table: T1  Alias: T1  
  54.     resc: 3.00  card: 99.01  bytes: 6  deg: 1  resp: 3.00  
  55.     using dmeth: 2  #groups: 1  
  56.     Cost per ptn: 0.50  #ptns: 1  
  57.     hash_area: 256 (max=61338)   Hash join: Resc: 5.51  Resp: 5.51  [multiMatchCost=0.00]  
  58.   HA cost: 5.51                                                       ------------>HASH JOIN(HA Join) 方式最好的代价是5.51   
  59.      resc: 5.51 resc_io: 5.00 resc_cpu: 7617598                       ------------>并行执行cpu代价7617598   
  60.      resp: 5.51 resp_io: 5.00 resp_cpu: 7617598  
  61. Best:: JoinMethod: Hash                                               ------------>这里计算出最好的代价表连接是Hash   
  62.        Cost: 5.51  Degree: 1  Resp: 5.51  Card: 81.22  Bytes: 10  
  63. ***********************  
  64. Best so far: Table#: 0  cost: 2.0021  card: 82.0291  bytes: 328  
  65.              Table#: 1  cost: 5.5074  card: 81.2170  bytes: 810  
  66. ***********************  

第二部分 T1关联T 


[sql]
  1. ***********************  
  2. Join order[2]:  T1[T1]#1   T[T]#0  
  3. ***************  
  4. Now joining:  T[T]#0  
  5. ***************  
  6. NL Join  
  7.   Outer table: Card: 99.01  Cost: 3.00  Resp: 3.00  Degree: 1  Bytes: 6  
  8.   Inner table:  T  Alias: T  
  9.   Access Path: TableScan  
  10.     NL Join:  Cost: 2139.43  Resp: 2139.43  Degree: 1  
  11.       Cost_io: 2069.00  Cost_cpu: 1057393301  
  12.       Resp_io: 2069.00  Resp_cpu: 1057393301  
  13.   Access Path: index (index (FFS))  
  14.     Index: IND_T  
  15.     resc_io: 30.34  resc_cpu: 9409631  
  16.     ix_sel: 0.0000e+00  ix_sel_with_filters: 1  
  17.   Inner table:  T  Alias: T  
  18.   Access Path: index (FFS)  
  19.     NL Join:  Cost: 3069.06  Resp: 3069.06  Degree: 1  
  20.       Cost_io: 3007.00  Cost_cpu: 931611861  
  21.       Resp_io: 3007.00  Resp_cpu: 931611861  
  22. kkofmx: index filter:"T"."X"<100  
  23.   Access Path: index (AllEqJoinGuess)  
  24.     Index: IND_T  
  25.     resc_io: 1.00  resc_cpu: 8171  
  26.     ix_sel: 1.9740e-05  ix_sel_with_filters: 3.1964e-08  
  27.     NL Join (ordered): Cost: 102.06  Resp: 102.06  Degree: 1  
  28.       Cost_io: 102.00  Cost_cpu: 872287  
  29.       Resp_io: 102.00  Resp_cpu: 872287  
  30.   Best NL cost: 102.06                                             ------------>ENSTED LOOPS JOIN 方式最好的代价是102.06   
  31.           resc: 102.06 resc_io: 102.00 resc_cpu: 872287           
  32.           resp: 102.06 resp_io: 102.00 resp_cpu: 872287  
  33. Join Card:  81.22 = outer (99.01) * inner (82.03) * sel (0.01)  
  34. Join Card - Rounded: 81 Computed: 81.22  
  35. SM Join  
  36.   Outer table:  
  37.     resc: 3.00  card 99.01  bytes: 6  deg: 1  resp: 3.00  
  38.   Inner table:  T  Alias: T  
  39.     resc: 2.00  card: 82.03  bytes: 4  deg: 1  resp: 2.00  
  40.     using dmeth: 2  #groups: 1  
  41.     SORT resource      Sort statistics  
  42.       Sort width:        1435 Area size:     1048576 Max Area size:   251238400  
  43.       Degree:               1  
  44.       Blocks to Sort:       1 Row size:           15 Total Rows:             82  
  45.       Initial runs:         1 Merge passes:        0 IO Cost / pass:          0  
  46.       Total IO sort cost: 0      Total CPU sort cost: 15035869  
  47.       Total Temp space used: 0  
  48.   SM join: Resc: 6.01  Resp: 6.01  [multiMatchCost=0.00]  
  49.   SM cost: 6.01                                                  ------------>SORT MERGE JOIN(SM Join) 方式最好的代价是6.01   
  50.      resc: 6.01 resc_io: 5.00 resc_cpu: 15125076  
  51.      resp: 6.01 resp_io: 5.00 resp_cpu: 15125076  
  52. HA Join  
  53.   Outer table:  
  54.     resc: 3.00  card 99.01  bytes: 6  deg: 1  resp: 3.00  
  55.   Inner table:  T  Alias: T  
  56.     resc: 2.00  card: 82.03  bytes: 4  deg: 1  resp: 2.00  
  57.     using dmeth: 2  #groups: 1  
  58.     Cost per ptn: 0.50  #ptns: 1  
  59.     hash_area: 256 (max=61338)   Hash join: Resc: 5.51  Resp: 5.51  [multiMatchCost=0.00]  
  60.   HA cost: 5.51                                                ------------>HASH JOIN(HA Join) 方式最好的代价是5.51   
  61.      resc: 5.51 resc_io: 5.00 resc_cpu: 7618448                ------------>并行执行cpu代价 7618448 高于 上一种表连接方式的(7617598)   
  62.      resp: 5.51 resp_io: 5.00 resp_cpu: 7618448  
  63. Join order aborted: cost > best plan cost  
  64. ***********************  
  65. (newjo-stop-1) k:0, spcnt:0, perm:2, maxperm:2000  
  66. *********************************  
  67. Number of join permutations tried: 2  
  68. *********************************  
  69. (newjo-save)    [1 0 ]  
  70. Final - All Rows Plan:  Best join order: 1                     ------------>第一种关联顺序   
  71.   Cost: 5.5074  Degree: 1  Card: 81.0000  Bytes: 810  
  72.   Resc: 5.5074  Resc_io: 5.0000  Resc_cpu: 7617598  
  73.   Resp: 5.5074  Resp_io: 5.0000  Resc_cpu: 7617598  
  74. kkoipt: Query block SEL$1 (#0)  
  75. ******* UNPARSED QUERY IS *******  
  76. SELECT "T1"."X" "X","T1"."NAME" "NAME" FROM "SYS"."T" "T","SYS"."T1" "T1" WHERE "T"."X"<100 AND "T1"."X"<100 AND "T"."X"="T1"."X"  
  77. kkoqbc-subheap (delete addr=0x2b4f6501c000, in-use=24512, alloc=26368)  
  78.   
  79. 集中关联方式的代价如下:  
  80.         T关联T1                  代价  
  81.     ENSTED LOOPS JOIN(NL Join)     100.24  
  82.     SORT MERGE JOIN(SM Join)    6.01  
  83.     HASH JOIN(HA Join)            5.51  
  84.       
  85.         T1关联T  
  86.     ENSTED LOOPS JOIN(NL Join)    102.06  
  87.     SORT MERGE JOIN(SM Join)    6.01  
  88.     HASH JOIN(HA Join)            5.51  
  89.      
linux
相关资讯       Oracle基础教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

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