Invisible Index In Oracle Database
Invisible index is introduced in oracle 11g. This type of index will be ignored by database optimizer, as if it doesn’t exists.
oracle configurationintermediate
by OracleDba
17 views
Invisible index is introduced in oracle 11g. This type of index will be ignored by database optimizer, as if it doesn’t exists.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
SQL> select count(*) from emp;
COUNT(*)
----------
90323
SQL> create index EMP_ID1 on TESTUSER.EMP(OBJECT_ID);
Index created.
SQL> select index_name,VISIBILITY from dba_indexes where index_NAME='EMP_ID1';
INDEX_NAME VISIBILIT
------------------- ---------
EMP_ID1 VISIBLE
SQL> explain plan for select count(*) from TESTUSER.emp where object_id=1;
Explained.
SQL> select * from table(dbms_xplan.display)
2 ;
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
Plan hash value: 853747123
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 5 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 5 | | |
|* 2 | INDEX RANGE SCAN| EMP_ID1 | 1 | 5 | 1 (0)| 00:00:01 | -->>> INDEX USED
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"=1)
14 rows selected.
SQL> alter index EMP_ID1 invisible;
Index altered.
SQL> select index_name,VISIBILITY from dba_indexes where index_NAME='EMP_ID1';
INDEX_NAME VISIBILIT
------------------- ---------
EMP_ID1 INVISIBLE
SQL> explain plan for select count(*) from TESTUSER.emp where object_id=1;
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
Plan hash value: 2083865914
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 5 | 149 (2)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 5 | | |
|* 2 | TABLE ACCESS FULL| EMP | 1 | 5 | 149 (2)| 00:00:01 | -->> FULL TABLE SCAN
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("OBJECT_ID"=1)
14 rows selected.1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
SQL> create index EMP_IDINV on TESTUSER.EMP(OBJECT_ID) invisble;
SQL> select index_name,VISIBILITY from dba_indexes where index_NAME='EMP_IDINV';
INDEX_NAME VISIBILIT
------------------- ---------
EMP_IDINV INVISIBLE
SQL> show parameter invi
NAME TYPE VALUE
------------------------------------ ----------- --------------------
optimizer_use_invisible_indexes boolean FALSE
SQL> alter system set optimizer_use_invisible_indexes=TRUE scope=both;
System altered.
SQL> show parameter optimizer_use_invisible_indexes
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_use_invisible_indexes boolean TRUE
SQL>
SQL> select index_name,VISIBILITY from dba_indexes where index_NAME='EMP_ID1';
INDEX_NAME VISIBILIT
------------------- ---------
EMP_ID1 INVISIBLE
SQL> explain plan for select count(*) from TESTUSER.emp where object_id=1;
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
Plan hash value: 853747123
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 5 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 5 | | |
|* 2 | INDEX RANGE SCAN| EMP_ID1 | 1 | 5 | 1 (0)| 00:00:01 | --- >>>>>> INDEX USED
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"=1)
14 rows selected.Please to add comments
No comments yet. Be the first to comment!