WINDOWS下的程序员出身,偶尔也写一些linux平台下小程序, 后转行数据库行业,专注于ORACLE和DB2的运维和优化。 同时也是ios移动开发者。欢迎志同道合的朋友一起研究技术。 数据库技术交流群:58308065,23618606
全部博文(599)
分类: Oracle
2010-09-26 14:41:21
不可见索引是11G的新特性,不可见并非物理上看不见,其实还是存在的。ORACLE
还会进行维护,只是ORACLE并不会使用它。 这在维护索引的时候非常有用,譬如,可以把
这个索引标志为不可见,看看系统的性能如何。如果没人使用到索引,可以DROP掉了,如果有人要用到这个索引,可以在标记为可见。省去了假设性能不好在重建对系统的影响。
SQL> conn TEST/test
Connected.
SQL> desc t
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER(38)
NAME VARCHAR2(30)
SQL> create index idx_t_01 on t(id) invisible;
Index created.
SQL> exec dbms_stats.gather_table_stats(user,'t',cascade=>true);
PL/SQL procedure successfully completed.
SQL> select index_name,visibility from user_indexes;
INDEX_NAME VISIBILIT
------------------------------ ---------
IDX_T_01 INVISIBLE
SQL> set autot traceonly exp
SQL> set linesize 200
SQL> select * from t where id=1;
Execution Plan
----------------------------------------------------------
Plan hash value: 1601196873
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 22 | 13 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T | 1 | 22 | 13 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ID"=1)
SQL> set autot off
SQL> alter index idx_t_01 visible;
Index altered.
SQL> select index_name,visibility from user_indexes;
INDEX_NAME VISIBILIT
------------------------------ ---------
IDX_T_01 VISIBLE
SQL> set autot traceonly exp
SQL> select * from t where id=1;
Execution Plan
----------------------------------------------------------
Plan hash value: 488553849
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 22 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 22 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_T_01 | 1 | | 1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=1)
SQL>
chinaunix网友2010-09-27 11:03:31
很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com