不可见索引和虚拟索引。(二)

2014-11-24 17:08:09 · 作者: · 浏览: 1
index(EMP_IDX1)*/ * FROM EMP WHERE EMPNO=7902; Execution Plan ---------------------------------------------------------- Plan hash value: 3956160932 -------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 32 | 6 (0)| 00:00:01 | |* 1 | TABLE ACCESS FULL| EMP | 1 | 32 | 6 (0)| 00:00:01 | -------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("EMPNO"=7902) SQL> SHOW parameter optimizer_use_ ORA-00942: table or view does not exist SQL> conn sys/root as sysdba Connected. SQL> show parameter optimizer_use NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ optimizer_use_invisible_indexes boolean FALSE optimizer_use_pending_statistics boolean FALSE optimizer_use_sql_plan_baselines boolean TRUE SQL> conn amy/rhys Connected. SQL> alter session set optimizer_use_invisible_indexes=true; Session altered. SQL> set autotrace trace exp SQL> select * from emp where empno=7902; Execution Plan ---------------------------------------------------------- Plan hash value: 3085206398 ---------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 32 | 2 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 32 | 2 (0)| 00:00:01 | |* 2 | INDEX RANGE SCAN | EMP_IDX1 | 1 | | 1 (0)| 00:00:01 | ---------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("EMPNO"=7902) SQL> alter session set optimizer_use_invisible_indexe=false; alter session set optimizer_use_invisible_indexe=false * ERROR at line 1: ORA-02248: invalid option for ALTER SESSION SQL> alter session set optimizer_use_invisible_indexes=false; Session altered. SQL> select * from emp where empno=7902; Execution Plan ---------------------------------------------------------- Plan hash value: 3956160932 -------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 32 | 6 (0)| 00:00:01 | |* 1 | TABLE ACCESS FULL| EMP | 1 | 32 | 6 (0)| 00:00:01 | -------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("EMPNO"=7902) SQL>

对于维护不可见索引和其他B树索引没有不同,后续将准备在索引维护内容进行学习。

虚拟索引:

 虚拟索引顾名思义,就是虚拟的索引不存在段的索引,注意:该索引在数据库中并不存在真正的物理存储信息,而是只是一个定义(有点类似于外部表的定义)信息,当我们测试一个潜在的索引是否对sql执行有效时,如果不是一个大表那么建议使用不可见索引,而对于大表只是为了测试优化器是否使用该索引而不想等到索引创建完就开始测试,那么可以使用该虚拟索引。对于索引创建测试更推荐使用不可