Oracle 11g: Invisible Indexes

php中文网
发布: 2016-06-07 17:28:05
原创
1408人浏览过

Oracle 11g 允许将索引标记为invisible. oracle像维护其他索引一样维护 invisible index ,但是默认invisible index不能被优化器

oracle 11g 允许将索引标记为invisible. oracle像维护其他索引一样维护 invisible index ,但是默认invisible index不能被优化器使用,,除非显式设置 optimizer_use_invisible_indexes=true(可以alter system/session).可以在创建索引的时候指定 invisible关键字或 alter index命令来invisible一个索引。
 
create index idx_name on table_name(column_name) invisible;
alter index idx_name invisible;
alter index idx_name visible;

demo:

SQL> create table ii_tab( id number);

Table created.

SQL> begin     
  for i in 1 .. 10000 loop
  insert into ii_tab values (i);
  end loop;
  commit;
  end;
  /

PL/SQL procedure successfully completed.

SQL> create index ii_tab_id on ii_tab(id) invisible;

Index created.

SQL> exec dbms_stats.gather_table_stats(USER,'ii_tab',cascade=>TRUE);

PL/SQL procedure successfully completed.

SQL> set autotrace on
SQL> select * from ii_tab where id=9999;

        ID
----------

 

Execution Plan
----------------------------------------------------------
Plan hash value: 2057286804

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

Predicate Information (identified by operation id):
---------------------------------------------------
 - filter("ID"=9999)


Statistics
----------------------------------------------------------
  recursive calls
  db block gets
  consistent gets
  physical reads
  redo size
  bytes sent via SQL*Net to client
  bytes received via SQL*Net from client
  SQL*Net roundtrips to/from client
  sorts (memory)
  sorts (disk)
  rows processed

SQL> alter session set optimizer_use_invisible_indexes=true;

Session altered.

SQL> select * from ii_tab where id=9999;

        ID
----------

 

Execution Plan
----------------------------------------------------------
Plan hash value: 81730945

------------------------------------------------------------------------------
| Id  | Operation        | Name      | Rows  | Bytes | Cost (%CPU)| Time    |
------------------------------------------------------------------------------
|  0 | SELECT STATEMENT |          |    1 |    4 |    1  (0)| 00:00:01 |
|*  1 |  INDEX RANGE SCAN| II_TAB_ID |    1 |    4 |    1  (0)| 00:00:01 |
------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
 - access("ID"=9999)


Statistics
----------------------------------------------------------
  recursive calls
  db block gets
  consistent gets
  physical reads
  redo size
  bytes sent via SQL*Net to client
  bytes received via SQL*Net from client
  SQL*Net roundtrips to/from client
  sorts (memory)
  sorts (disk)
  rows processed

SQL> alter session set optimizer_use_invisible_indexes=false;

Session altered.

可以看到即使设置索引为invisible,当optimizer_use_invisible_indexes为true的时候 优化器仍然会走索引而非全表。
 
对比一下 ALTER INDEX ... UNUSABLE, 优化器不会使用UNUSABLE索引,需要 REBUILD

linux

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 //m.sbmmt.com/ All Rights Reserved | php.cn | 湘ICP备2023035733号