索引与Null值对Hints及执行计划的影响(2)

文章作者 100test 发表时间 2007:03:14 13:51:28
来源 100Test.Com百考试题网


索引字段允许为null时,oracle放弃此索引:

sql> alter table t modify (username null).
table altered.
sql> 0select /*  index(t,i_t) */ * from t.
execution plan
----------------------------------------------------------
plan hash value: 1601196873
--------------------------------------------------------------------------
| id | operation | name | rows | bytes | cost (%cpu)| time |
--------------------------------------------------------------------------
| 0 | 0select statement | | 27 | 918 | 2 (0)| 00:00:01 |
| 1 | table access full| t | 27 | 918 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------
note
-----
- dynamic sampling used for this statement

当该字段为not null时,索引可以被强制使用:

sql> alter table t modify (username not null).
table altered.
sql> 0select /*  index(t,i_t) */ * from t.
execution plan
----------------------------------------------------------
plan hash value: 3593393735
------------------------------------------------------------------------------------
| id | operation | name | rows | bytes | cost (%cpu)| time |
------------------------------------------------------------------------------------
| 0 | 0select statement | | 27 | 918 | 2 (0)| 00:00:01 |
| 1 | table access by index rowid| t | 27 | 918 | 2 (0)| 00:00:01 |
| 2 | index full scan | i_t | 27 | | 1 (0)| 00:00:01 |
------------------------------------------------------------------------------------
note
-----
- dynamic sampling used for this statement

这就是null值对于索引及查询的影响.



相关文章


在OracleXE构建GoogleEarth接口(2)
ORACLE应用中常见的傻瓜问题1000问(二)
如何有效应用时间的有限和无限
在OracleXE构建GoogleEarth接口(1)
索引与Null值对Hints及执行计划的影响(2)
索引与Null值对Hints及执行计划的影响(1)
如何在Oracle数据库字段上建立索引
教你如何优化Oracle的网络设置
如何使用Oracle的BFILE(2)
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛