视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
Oracle11g:InvisibleIndexes
2020-11-09 10:50:26 责编:小采
文档


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

下载本文
显示全文
专题