| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| T | 1 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement (level=2)
可以看到,优化器不会使用在列Y,Z上建立的索引来查询行数。实际上也不能使用,这是因为B*Tree索引不会为完全为NULL的索引键建立条目,Y和Z虽然加了不为NULL的约束,但是是延迟约束,也就是允许临时为NULL,所以优化器无法使用它们来查询行数。
还有,如果创建1个unique或者primary key约束,oracle会为这个约束创建1个唯一索引。但是如果创建1个延迟unique或者primary key约束,由于可以临时忽略约束,oracle就只能创建1个非唯一索引。
例如:
view plain
tony@ORA11GR2> drop table t;
Table dropped.
tony@ORA11GR2> create table t(x int primary key);
Table created.
tony@ORA11GR2> select index_name, uniqueness from user_indexes where table_name='T';
INDEX_NAME UNIQUENESS
------------------------------------------------------------ ------------------
SYS_C0011412 UNIQUE
tony@ORA11GR2> drop table t;
Table dropped.
tony@ORA11GR2> create table t(x int primary key deferrable);
Table created.
tony@ORA11GR2> select index_name, uniqueness from user_indexes where table_name='T';
INDEX_NAME UNIQUENESS
------------------------------------------------------------ ------------------
SYS_C0011413 NONUNIQUE
摘自 NowOrNever