设为首页 加入收藏

TOP

Oracle不使用索引的几种情况列举(四)
2017-01-24 08:15:17 】 浏览:609
Tags:Oracle 使用 索引 情况 列举
--------
| Id? | Operation? ? ? ? ? | Name | Rows? | Cost (%CPU)| Time? ? |
-------------------------------------------------------------------
|? 0 | SELECT STATEMENT? |? ? ? |? ? 1 |? 153? (1)| 00:00:02 |
|? 1 |? SORT AGGREGATE? ? |? ? ? |? ? 1 |? ? ? ? ? ? |? ? ? ? ? |
|? 2 |? TABLE ACCESS FULL| T? ? | 99999 |? 153? (1)| 00:00:02 |
-------------------------------------------------------------------
?
zx@ORCL>alter table t modify y not null;
?
Table altered.
?
zx@ORCL>desc t
?Name? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Null?? ? Type
?----------------------------------------------------------------------------------------------------- -------- --------------------------------------------------------------------
?X? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NUMBER
?Y? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NOT NULL NUMBER
?Z? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CHAR(23)
?
zx@ORCL>select count(*) from t;
?
Execution Plan
----------------------------------------------------------
Plan hash value: 2371838348
?
-----------------------------------------------------------------------
| Id? | Operation? ? ? ? ? ? | Name? | Rows? | Cost (%CPU)| Time? ? |
-----------------------------------------------------------------------
|? 0 | SELECT STATEMENT? ? ? |? ? ? |? ? 1 |? ? 80? (0)| 00:00:01 |
|? 1 |? SORT AGGREGATE? ? ? |? ? ? |? ? 1 |? ? ? ? ? ? |? ? ? ? ? |
|? 2 |? INDEX FAST FULL SCAN| IDX_T | 99999 |? ? 80? (0)| 00:00:01 |
-----------------------------------------------------------------------


情况3:
对于一个有索引的列,做以下查询:
select * from t where function(indexed_column)=value;
却发现没有使用indexed_colum上的索引。原因是这个列上使用了函数。如果是对indexed_column的值建立了索引,而不是对function(indexed_column)的值建索引。在此不能使用这个索引。如果愿意,可以另外对函数建立索引。
zx@ORCL>select * from t where mod(x,999)=1;
?
Execution Plan
----------------------------------------------------------
Plan hash value: 1601196873
?
--------------------------------------------------------------------------
| Id? | Operation? ? ? ? | Name | Rows? | Bytes | Cost (%CPU)| Time? ? |
--------------------------------------------------------------------------
|? 0 | SELECT STATEMENT? |? ? ? |? 1000 | 34000 |? 153? (1)| 00:00:02 |
|*? 1 |? TABLE ACCESS FULL| T? ? |? 1000 | 34000 |? 153? (1)| 00:00:02 |
--------------------------------------------------------------------------
?
Predicate Information (identified by operation id):
---------------------------------------------------
?
? 1 - filter(MOD("X",999)=1)
?
zx@ORCL>create index idx_t_f on t(mod(x,999));
?
Index created.
?
zx@ORCL>exec dbms_stats.gather_table_stats(USER,'T',cascade=>true);
?
PL/SQL procedure successfully completed.
?
zx@ORCL>select * from t where mod(x,999)=1;
?
Execution Plan
----------------------------------------------------------
Plan hash value: 4125918735
?
---------------------------------------------------------------------------------------
| Id? | Operation? ? ? ? ? ? ? ? ? | Name? ? | Rows? | Bytes | Cost (%CPU)| Time? ? |
---------------------------------------------------------------------------------------
|? 0 | SELECT STATEMENT? ? ? ? ? ? |? ? ? ? |? 100 |? 3800 |? 102? (0)| 00:00:02 |
|? 1 |? TABLE ACCESS BY INDEX ROWID| T? ? ? |? 100 |? 3800 |? 102? (0)| 00:00:02 |
|*? 2 |? INDEX RANGE SCAN? ? ? ? ? | IDX_T_F |? 100 |? ? ? |? ? 1? (0)| 00:00:01 |
---------------------------------------------------------------------------------

首页 上一页 1 2 3 4 5 6 下一页 尾页 4/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇RMAN无法删除归档日志 下一篇Oracle order by子句对NULL的排序

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目