To make the Index “VISIBLE”
ALTER INDEX index VISIBLE;
A new column “VISIBILITY” is available in *_INDEXES data dictionary views to know if an index is visible or invisible.
Index created.
SQL> explain plan for select * from emp1 where job='CLERK';
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3449298850
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 348 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMP1 | 4 | 348 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | INDX_JOB | 4 | | 1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------
SQL> explain plan for select * from emp1 where job='CLERK';
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 2226897347
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 348 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| EMP1 | 4 | 348 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
SQL> ALTER SESSION SET optimizer_use_invisible_indexes=TRUE;
Session altered.
SQL> select index_name,visibility from user_indexes where table_name='EMP1';
INDEX_NAME VISIBILIT
------------------------------ ---------
INDX_JOB INVISIBLE
SQL> explain plan for select * from emp1 where job='CLERK';
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3449298850
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 348 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMP1 | 4 | 348 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | INDX_JOB | 4 | | 1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------