Oracle:如何检查索引状态?

4
我在字段 createdate 上创建了索引 createdate_idx,然后进行了以下查询:

select * from tablename where createdate>=to_date('2016-02-29','yyyy-mm-dd');

但是我不确定索引 createdate_idx 是否被使用。如何确认是否使用了该索引?
3个回答

4

EXPLAIN PLAN 可以展示使用了哪个索引以及其他相关信息。

例如:

explain plan for
select * from tablename where createdate>=to_date('2016-02-29','yyyy-mm-dd');

select * from table(dbms_xplan.display);

Plan hash value: 3955337982

-------------------------------------------------------------------------------
| Id  | Operation         | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |           |     1 |     9 |     2   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| TABLENAME |     1 |     9 |     2   (0)| 00:00:01 |
-------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("CREATEDATE">=TO_DATE(' 2016-02-29 00:00:00', 
              'syyyy-mm-dd hh24:mi:ss'))

Note
-----
   - dynamic statistics used: dynamic sampling (level=2)

1
explain plan会显示使用了哪个索引以及其他信息。 注意:在查询中使用索引所在的列值,以查看从表格(dbms_xplan.display)选择的信息。
  1. 如果没有,请创建索引:create index ind on emp(empno);
  2. explain plan for select * from emp where empno >1100;
  3. select * from table(dbms_xplan.display);

enter image description here


1

可以通过查询Oracle系统视图来检查索引状态:

select TABLE_NAME, INDEX_NAME, STATUS from USER_INDEXES where TABLE_NAME like '%';

STATUS 字段的值为 N/A 时,表示该索引已分区。可以使用以下查询检查各个索引分区的状态:

select INDEX_NAME, PARTITION_NAME, STATUS from USER_IND_PARTITIONS where INDEX_NAME like '%';

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接