在数据库优化过程中,索引的重要性是不言而喻的,但是在我们进行性能调整过程中, 一个索引是否能够被使用到,在索引创建之前是存在不确定性的。
而创建索引又是一个代价很高的操作,尤其是数据量很大的情况下,在11g环境下我们就可以考虑使用虚拟索引,预估索引的效果。
alter session set "_use_nosegment_indexes" = true; create index idx_tkk1207_query on tkk1207(ownerid) nosegment; explain plan for select * from tkk1207 t where t.ownerid = 'xxx'; select * from table(dbms_xplan.display());
效果不错!!
PLAN_TABLE_OUTPUT -----------------------------------------------------------------------------------------------------------------------------Plan hash value: 123941074 ------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 44 | 98K| 5 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID| TKK1207 | 44 | 98K| 5 (0)| 00:00:01 | |* 2 | INDEX RANGE SCAN | IDX_TKK1207_QUERY | 631 | | 1 (0)| 00:00:01 | ------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): PLAN_TABLE_OUTPUT ----------------------------------------------------------------------------------------------------------------------------- 2 - access("OWNERID"='xx') Note ----- - dynamic sampling used for this statement (level=2)
索引验证有效后,删除该虚拟索引,在业务低峰期创建真实的索引。
drop index idx_tkk1207_query; create index idx_tkk1207_query on tkk1207(ownerid) online nologging parallel 4; alter index idx_tkk1207_query noparallel;