三:在前面的测试中,1-5999之间的查询,为什么不选择分区范围扫描?1000-5000之间的查询,为什么不选择全表扫描,使用索引,不会产生无谓的2次I/O吗?要了解这些,就要开启数据库的10053时间,分析cbo如何选择执行计划?
1:分析1-5999之间查询的10053事件
- SQL> alter session set tracefile_identifier='HR03';
- Session altered.
- SQL> alter session set events '10053 trace name context forever,level 1';
- Session altered.
- SQL> select object_id,count(*) from t2 where object_id between 1 and 5999 group by object_id;
- 5807 rows selected.
- SQL> alter session set events '10053 trace name context off';
- Session altered.
trace文件关键内容:
| *************************************** Column Usage Monitoring is ON: tracking level = 1 *************************************** **************** QUERY BLOCK TEXT **************** select object_id,count(*) from t2 where object_id between 1 and 5999 group by object_id ********************* QUERY BLOCK SIGNATURE ********************* qb name was generated signature (optimizer): qb_name=SEL$1 nbfros=1 flg=0 fro(0): flg=0 objn=54910 hint_alias="T2"@"SEL$1" ***************************** SYSTEM STATISTICS INFORMATION ***************************** Using NOWORKLOAD Stats CPUSPEED: 587 millions instruction/sec IOTFRSPEED: 4096 bytes per millisecond (default is 4096) IOSEEKTIM: 10 milliseconds (default is 10) *************************************** BASE STATISTICAL INFORMATION *********************** Table Stats:: Table: T2 Alias: T2 (Using composite stats) (making adjustments for partition skews) ORIGINAL VALUES:: #Rows: 15078669 #Blks: 71051 AvgRowLen: 28.00 PARTITIONS:: PRUNED: 2 ANALYZED: 2 UNANALYZED: 0 #Rows: 15078669 #Blks: 10756 AvgRowLen: 28.00 Index Stats:: Index: I_T_ID Col#: 1 USING COMPOSITE STATS LVLS: 2 #LB: 33742 #DK: 50440 LB/K: 1.00 DB/K: 303.00 CLUF: 15299802.00 Column (#1): OBJECT_ID(NUMBER) AvgLen: 5.00 NDV: 50440 Nulls: 0 Density: 1.9826e-05 Min: 33 Max: 54914 *************************************** SINGLE TABLE ACCESS PATH Table: T2 Alias: T2 Card: Original: 15078669 Rounded: 1639470 Computed: 1639469.86 Non Adjusted: 1639469.86 Access Path: TableScan Cost: 2432.43 Resp: 2432.43 Degree: 0 Cost_io: 2355.00 Cost_cpu: 545542277 Resp_io: 2355.00 Resp_cpu: 545542277 Access Path: index (index (FFS)) Index: I_T_ID resc_io: 7383.00 resc_cpu: 2924443977 ix_sel: 0.0000e+00 ix_sel_with_filters: 1 Access Path: index (FFS) Cost: 7798.09 Resp: 7798.09 Degree: 1 Cost_io: 7383.00 Cost_cpu: 2924443977 Resp_io: 7383.00 Resp_cpu: 2924443977 Access Path: index (IndexOnly) Index: I_T_ID resc_io: 3671.00 resc_cpu: 358846806 ix_sel: 0.10873 ix_sel_with_filters: 0.10873 Cost: 3721.93 Resp: 3721.93 Degree: 1 Best:: AccessPath: TableScan Cost: 2432.43 Degree: 1 Resp: 2432.43 Card: 1639469.86 Bytes: 0 Grouping column cardinality [ OBJECT_ID] 5484 |
