ITPub博客

首页 > 数据库 > Oracle > 新增一个索引,而不影响其他应用

新增一个索引,而不影响其他应用

Oracle 作者:shoujdx1 时间:2014-11-12 07:15:10 0 删除 编辑
SQL> select * from test;


        ID
----------
         1
         2
         3
         4
         5
1.将索引创建为不可见
SQL> create index test_idx1 on test(id) invisible;


Index created.

2.指示优化器考虑不可见索引
SQL> alter system set optimizer_use_invisible_indexes=true;


System altered.

3.查看执行计划
SQL> set autotrace trace explain
SQL> select id from test where id=2;


Execution Plan
----------------------------------------------------------
Plan hash value: 4100545912


------------------------------------------------------------------------------
| Id  | Operation        | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------
|   0 | SELECT STATEMENT |           |     1 |    13 |     1   (0)| 00:00:01 |
|*  1 |  INDEX RANGE SCAN| TEST_IDX1 |     1 |    13 |     1   (0)| 00:00:01 |
------------------------------------------------------------------------------


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


   1 - access("ID"=2)


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


4.不用的时候,让优化器忽略不可见索引
SQL> alter system set optimizer_use_invisible_indexes=false;


System altered.


SQL> select id from test where id=2;


Execution Plan
----------------------------------------------------------
Plan hash value: 1357081020


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


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


   1 - filter("ID"=2)


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


-----------------------------------
kingsql分享
hongzhuohui@kingsql.com
转载请注明出处

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29266954/viewspace-1329170/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-11-09

  • 博文量
    16
  • 访问量
    14632