方式作为最终的执行计划,即T关联T1通过Hash Join的方式来做关联的代价最小。
下面这个部分是通过CBO给出的一个执行计划报告,其中ROWS例对应于上面每个操作的 cardinality rounded cost 对应于每一个操作的cost值。
============
Plan Table
============
------------------------------------------------+-----------------------------------+
| Id | Operation | Name | Rows | Bytes | Cost | Time |
------------------------------------------------+-----------------------------------+
| 0 | SELECT STATEMENT | | | | 6 | |
| 1 | HASH JOIN | | 81 | 810 | 6 | 00:00:01 |
| 2 | INDEX RANGE SCAN | IND_T | 82 | 328 | 2 | 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID | T1 | 99 | 594 | 3 | 00:00:01 |
| 4 | INDEX RANGE SCAN | IND_T1 | 99 | | 2 | 00:00:01 |
------------------------------------------------+-----------------------------------+
Predicate Information:
----------------------
1 - access("T"."X"="T1"."X")
2 - access("T"."X"<100)
4 - access("T1"."X"<100)
Content of other_xml column
===========================
db_version : 10.2.0.4
parse_schema : SYS
plan_hash : 2145127414
Outline Data:
通过一系列的计算和比较,CBO最终选择了上面的执行计划作为SQL的最终执行计划。trace文件最后,这里不做讨论。
下面是帮一个网友看的一个问题
这个是测试环境,走索引的
Single Table Cardinality Estimation for CLAIMS[CLAIMS]
Table: CLAIMS Alias: CLAIMS
Card: Original: 100817.000000 Rounded: 6470 Computed: 6469.52 Non Adjusted: 6469.52
Access Path: TableScan
Cost: 2845.00 Resp: 2845.00 Degree: 0
Cost_io: 2805.00 Cost_cpu: 662177710
Resp_io: 2805.00 Resp_cpu: 662177710
Access Path: index (RangeScan)
Index: CLAIMS_IDX16
resc_io: 6904.60 resc_cpu: 275804847
ix_sel: 0.333333 ix_sel_with_filters: 0.333333
Cost: 6921.26 Resp: 6921.26 Degree: 1
Access Path: index (RangeScan)
Index: CLAIMS_IDX30
resc_io: 3346.60 resc_cpu: 171975781
ix_sel: 0.500000 ix_sel_with_filters: 0.500000
Cost: 3356.98 Resp: 3356.98 Degree: 1
****** trying bitmap/domain indexes ******
Access Path: index (AllEqRange)
Index: CLAIMS_IDX16
resc_io: 46.00 resc_cpu: 3689036
ix_sel: 0.166667 ix_sel_with_filters: 0.166667
Cost: 46.22 Resp: 46.22 Degree: 0
Access Path: index (AllEqRange)
Index: CLAIMS_IDX16
resc_io: 46.00 resc_cpu: 3689036
ix_sel: 0.166667 ix_sel_with_filters: 0.166667
Cost: 46.22 Resp: 46.22 Degree: 0
Access Path: index (AllEqRange)
Index: CLAIMS_IDX30
resc_io: 33.00 resc_cpu: 2589658
ix_sel: 0.250000 ix_sel_with_filters: 0.250000
Cost: 33.16 Resp: 33.16 Degree: 0
Access Path: index (AllEqRange)
Index: CLAIMS_IDX30
resc_io: 33.00 resc_cpu: 2589658
ix_sel: 0.250000 ix_sel_with_filters: 0.250000
Cost: 33.16 Resp: 33.16 Degree: 0
Access path: Bitmap index - accepted
Cost: 2730.185047 Cost_io: 2721.380943 Cost_cpu: 145743285.440609 Sel: 0.166667
Not Believed to be index-only
****** finished trying bitmap/domain indexes ******
******** Begin index join costing ********
******** End index join costing ********
Best:: AccessPath: IndexBitmap
Cost: 2730.19 Degree: 1 Resp: 2730.19 Card: 6469.52 Bytes: 0
这个是真实环境,不走索引
Single Table Cardinality Estimation for CLAIMS[CLAIMS]
Table: CLAIMS Alias: CLAIMS
Card: Original: 101522.000000 Rounded: 6570 Computed: 6570.11 Non Adjusted: 6570.11
Access Path: TableScan
Cost: 5949.01 Resp: 5949.01 Degree: 0
Cost_io: 5900.00 Cost_cpu: 811350733
Resp_io: 5900.00 Resp_cpu: 811350733
Access Path: index (RangeScan)
Index: CLAIMS_IDX16
resc_io: 39801.47 resc_cpu: 514492135
ix_sel: 0.333333 ix_sel_with_filters: 0.333333
Cost: 39832.55 Resp: 39832.55 Degree: 1
Access Path: index (RangeScan)
Index: CLAIMS_IDX30
resc_io: 25940.30 resc_cpu: 344175912
ix_sel: 0.500000 ix_sel_with_filters: 0.500000
Cost: 25961.09 Resp: 25961.09 Degree: 1
Best:: AccessPath: TableScan
Cost: 5949.01 Degree: 1 Resp: 5949.01 Card: 6570.11 Bytes: 0
