-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 5106 | 30636 | 19 (0)| 00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID| BOOKS | 5106 | 30636 | 19 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | BOOK_IDX2 | 5106 | | 11 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("HOTEL_ID"=20)
2 - access("RATE_CATEGORY"=21)
该输出清晰地显示索引 BOOK_IDX2 已使用。为什么现在使用了索引?注意“Rows”列下方的值 (5106)。优化程序正确地确定了值组合的行数的估计值,而非分开的各个值的行数的估计值。
当然了,对于其他的条件,oracle也可以做出准确的判断
SQL> set autotrace trace exp
SQL> select hotel_id,rate_category from books where hotel_id=10 and rate_category=12;
Execution Plan
----------------------------------------------------------
Plan hash value: 2688610195
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 39385 | 230K| 47 (3)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| BOOKS | 39385 | 230K| 47 (3)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("RATE_CATEGORY"=12 AND "HOTEL_ID"=10)
在视图 USER_STAT_EXTENSIONS 中,您可以看到在数据库中定义的扩展统计信息:
SQL> select extension_name, extension
2 from user_stat_extensions
3 where table_name='BOOKS';
EXTENSION_NAME EXTENSION
------------------------------ --------------------------------------------------------------------------------
SYS_STUW3MXAI1XLZHCHDYKJ9E4K90 ("HOTEL_ID","RATE_CATEGORY")