T T_IND 50659 112 263
T1 T1_IND 50660 112 25899
我们看到数据分布在数据块上面越多,索引的聚合因子越高,聚合因子的值接近表的数据块的值。
[sql] view plaincopy
SQL> set autotrace traceonly
SQL> set linesize 200
SQL> select * from t where object_id<100;
98 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1376202287
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 80 | 2240 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 80 | 2240 | 3 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T_IND | 80 | | 2 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"<100)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
17 consistent gets --注意这里
0 physical reads
0 redo size
3051 bytes sent via SQL*Net to client
558 bytes received via SQL*Net from client
8 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
98 rows processed
SQL> select * from t1 where object_id<100;
99 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2059591622
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 69 | 1932 | 38 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 69 | 1932 | 38 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T1_IND | 69 | | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"<100)
Statistics
----------------------------------------------------------
150 recursive calls
0 db block gets
106 consistent gets --注意这里
0 physical reads
0 redo size
3061 bytes sent via SQL*Net to client
558 bytes received via SQL*Net from client
8 SQL*Net roundtrips to/from client
4 sorts (memory)
0 sorts (disk)
99 rows processed
我们看到同样的执行计划,索引的聚合因子高的sql(T1)表产生更多的一致性读操作了,执行计划的成本也提高了很多:
对象 一致性读 成本
T 17 3
T1 106 38
上面就是Custering Factor 对CBO计算执行计划的影响。
--------------------------------------------