oracle使索引不可见,oracle 不可见索引

#########################一.不可见索引########################## --1.新建不可见索引表 create table t1 ( sid int not null , sname varchar2(10) ) tablespace test; --循环导入数据 declare         maxrecords constant int:=100000;         i int :=1;     begin         for i in 1..maxrecords loop           insert into t1 values(i,'ocpyang');         end loop;     dbms_output.put_line(' 成功录入数据! ');     commit;     end;  / exec dbms_stats.gather_table_stats(user,'T1'); SQL> set autotrace on SQL> select * from t1 where sid=2001;        SID SNAME ---------- ----------       2001 ocpyang 执行计划 ---------------------------------------------------------- Plan hash value: 3617692013 -------------------------------------------------------------------------- | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     | -------------------------------------------------------------------------- |   0 | SELECT STATEMENT  |      |     1 |    13 |   103   (1)| 00:00:02 | |*  1 |  TABLE ACCESS FULL| T1   |     1 |    13 |   103   (1)| 00:00:02 | -------------------------------------------------------------------------- Predicate Information (identified by operation id): ---------------------------------------------------    1 - filter("SID"=2001) Note -----    - SQL plan baseline "SQL_PLAN_d1c0fjvcgamm5dbd90e8e" used for this statement 统计信息 ----------------------------------------------------------           1  recursive calls           1  db block gets         272  consistent gets           0  physical reads           0  redo size         598  bytes sent via SQL*Net to client         520  bytes received via SQL*Net from client           2  SQL*Net roundtrips to/from client           0  sorts (memory)           0  sorts (disk)           1  rows processed SQL> create index index_01 on t1(sid) invisible; SQL> select * from t1 where sid=2001;        SID SNAME ---------- ----------       2001 ocpyang 执行计划 ---------------------------------------------------------- Plan hash value: 3617692013 -------------------------------------------------------------------------- | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     | -------------------------------------------------------------------------- |   0 | SELECT STATEMENT  |      |     1 |    13 |   103   (1)| 00:00:02 | |*  1 |  TABLE ACCESS FULL| T1   |     1 |    13 |   103   (1)| 00:00:02 | -------------------------------------------------------------------------- Predicate Information (identified by operation id): ---------------------------------------------------    1 - filter("SID"=2001) Note -----    - SQL plan baseline "SQL_PLAN_d1c0fjvcgamm5dbd90e8e" used for this statement 统计信息 ----------------------------------------------------------           1  recursive calls           1  db block gets         272  consistent gets           0  physical reads           0  redo size         598  bytes sent via SQL*Net to client         520  bytes received via SQL*Net from client           2  SQL*Net roundtrips to/from client           0  sorts (memory)           0  sorts (disk)           1  rows processed SQL> 虽然新建了索引,但是数据库并没有使用. select index_name,visibility from dba_indexes where visibility='INVISIBLE'; INDEX_NAME                     VISIBILIT ------------------------------ --------- INDEX_01                       INVISIBLE --2.让优化器使用不可见索引 show parameters invisible; NAME                                 TYPE        VALUE ------------------------------------ ----------- -------------- optimizer_use_invisible_indexes      boolean     FALSE 默认情况下,优化器将不使用不可见索引. --设置让优化器使用不可见索引 alter session set optimizer_use_invisible_indexes=true;  --对当前会话生效 alter system set optimizer_use_invisible_indexes=true;  --对系统所有会话生效 set autotrace on exp; select /* index(index_01) */ * from t1 where sid=2001;        SID SNAME ---------- ----------       2001 ocpyang 执行计划 ---------------------------------------------------------- Plan hash value: 1514635137 -------------------------------------------------------------------------------- -------- | Id  | Operation        | Name     | Rows  | Bytes | Cost (%CPU)| Ti me     | -------------------------------------------------------------------------------- -------- |   0 | SELECT STATEMENT    |     |     1 |    13 |     2   (0)| 00:00:01 | |   1 |  TABLE ACCESS BY INDEX ROWID| T1  |     1 |    13 |     2   (0)| 00:00:01 | |*  2 |   INDEX RANGE SCAN | INDEX_01 | 1 |  | 1 (0)| 00  :00:01 |  --表明使用索引 -------------------------------------------------------------------------------- Predicate Information (identified by operation id): ---------------------------------------------------    2 - access("SID"=2001) set autotrace off;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值