使用NOSEGMENT創建測試索引

如果你想要創建一個很大的索引,但並不想給它分配空間,而是要先確定優化器是否會選擇使用該索引,那麼在11g中可以使用NOSEGMENT來創建索引就可以先進行測試。如果確定了這個索引是有用的,可以刪除該索引,然後使用不包含NOSEGMENT的語句重建它。

SQL> create index idx_emp on emp(employee_id) nosegment;

Index created.

SQL> set autot traceonly;
SQL> select * from APP.EMP t where t.employee_id='105';

Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932

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

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("T"."EMPLOYEE_ID"=105)

Note
-----
   - dynamic sampling used for this statement (level=2)


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

SQL> set autot off

SQL> ALTER SESSION SET "_use_nosegment_indexes"=true;  <----session級修改隱含參數_use_nosegment_indexes爲true

Session altered.

SQL>  set autot traceonly;
SQL> set lines 900
SQL> select * from APP.EMP t where t.employee_id='105';


Execution Plan
----------------------------------------------------------
Plan hash value: 306890541

---------------------------------------------------------------------------------------
| Id  | Operation                   | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |         |     1 |   133 |     2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| EMP     |     1 |   133 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | IDX_EMP |     1 |       |     1   (0)| 00:00:01 |
---------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("T"."EMPLOYEE_ID"=105)

Note
-----
   - dynamic sampling used for this statement (level=2)


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




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章