Oracle 11g新特性invisible index(不可见的索引)[通俗易懂]

Oracle 11g新特性invisible index(不可见的索引)

大家好,又见面了,我是全栈君。

    假设一张表上有十几个索引,你有什么感受?显然会拖慢增、删、改的速度。不要指望开发者能建好索引。我的处理方法是先监控非常长的一段时间。看哪些索引没实用到,然后删除。

但删除以后,假设发现某一天实用,那又要又一次建,假设是大表。那就有些麻烦。如今11g提供一个新特性,不可见索引。能够建索引设置为不可见索引。CBO在评估运行计划的时候会忽略它,假设须要的时候。设置回来就可以。

    另一种用途,你在调试一条SQL语句,要建一个索引測试。而你不想影响其它的会话,用不可见索引正是时候。

SQL> drop table test purge;

SQL> create table test as select * from dba_objects;
SQL> create index ind_t_object_id on test(object_id);
SQL> exec dbms_stats.gather_table_stats(user,’test’,cascade => true);
SQL> set autotrace traceonly
SQL> select * from test where object_id = 10;
运行计划
———————————————————-
Plan hash value: 255872589
———————————————————————————————–
| Id  | Operation                   | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
———————————————————————————————–
|   0 | SELECT STATEMENT            |                 |     1 |   100 |     2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| TEST            |     1 |   100 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | IND_T_OBJECT_ID |     1 |       |     1   (0)| 00:00:01 |
———————————————————————————————–
Predicate Information (identified by operation id):
—————————————————
   2 – access(“OBJECT_ID”=10)
统计信息
———————————————————-
          1  recursive calls
          0  db block gets
          4  consistent gets
          0  physical reads
          0  redo size
       1195  bytes sent via SQL*Net to client
        337  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

SQL> alter index ind_t_object_id invisible;
SQL> select * from test where object_id = 10;
运行计划
———————————————————-
Plan hash value: 1357081020
————————————————————————–
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
————————————————————————–
|   0 | SELECT STATEMENT  |      |     1 |   100 |   209   (1)| 00:00:03 |
|*  1 |  TABLE ACCESS FULL| TEST |     1 |   100 |   209   (1)| 00:00:03 |
————————————————————————–
Predicate Information (identified by operation id):
—————————————————
   1 – filter(“OBJECT_ID”=10)
统计信息
———————————————————-
        196  recursive calls
          0  db block gets
        567  consistent gets
          0  physical reads
          0  redo size
       1195  bytes sent via SQL*Net to client
        337  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          6  sorts (memory)
          0  sorts (disk)
          1  rows processed

SQL> select /*+ index(test ind_t_object_id)*/ * from test where object_id = 10;
运行计划
———————————————————-
Plan hash value: 1357081020
————————————————————————–
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
————————————————————————–
|   0 | SELECT STATEMENT  |      |     1 |   100 |   209   (1)| 00:00:03 |
|*  1 |  TABLE ACCESS FULL| TEST |     1 |   100 |   209   (1)| 00:00:03 |
————————————————————————–
Predicate Information (identified by operation id):
—————————————————
   1 – filter(“OBJECT_ID”=10)
统计信息
———————————————————-
          1  recursive calls
          0  db block gets
        544  consistent gets
          0  physical reads
          0  redo size
       1195  bytes sent via SQL*Net to client
        337  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

–让数据库看到不可见索引,能够通过改变一个參数
SQL> alter session set optimizer_use_invisible_indexes = true;
SQL> select * from test where object_id = 10;
运行计划
———————————————————-
Plan hash value: 255872589
———————————————————————————————–
| Id  | Operation                   | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
———————————————————————————————–
|   0 | SELECT STATEMENT            |                 |     1 |   100 |     2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| TEST            |     1 |   100 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | IND_T_OBJECT_ID |     1 |       |     1   (0)| 00:00:01 |
———————————————————————————————–
Predicate Information (identified by operation id):
—————————————————
   2 – access(“OBJECT_ID”=10)
统计信息
———————————————————-
          1  recursive calls
          0  db block gets
          4  consistent gets
          0  physical reads
          0  redo size
       1195  bytes sent via SQL*Net to client
        337  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/115714.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 什么是贝叶斯

    什么是贝叶斯原文地址[你对贝叶斯统计都有怎样的理解?](https://www.zhihu.com/question/21134457)浅谈贝叶斯不论是学习概率统计还是机器学习的过程中,贝叶斯总是是绕不过去的一道坎,大部分人在学习的时候都是在强行地背公式和套用方法,没有真正去理解其牛逼的思想内涵。我看了一下自己学校里一些涉及到贝叶斯统计的课程,content里的第一条都是PhilosophyofBaye

    2022年5月16日
    42
  • flink中文社区_flink demo

    flink中文社区_flink demoFeatureStagesMVP:Havealook,considerwhetherthiscanhelpyouinthefuture.Beta:Youcan…

    2025年6月16日
    2
  • mac进入路径_mac终端找不到命令

    mac进入路径_mac终端找不到命令如果你想将当前commandline会话切换到其他目录,需要用到三个命令:pwd,ls和cd。pwd的含义是“printworkingdirectory”,会显示当前目录的绝对路径。 ls的含义是“listdirectorycontents”,它会列出当前目录的内容。这个命令还有其他参数可选。 cd的含义是“changedirectory”,它会改变当…

    2022年10月10日
    2
  • WordPress中文汉字username不能注冊怎么办?

    WordPress中文汉字username不能注冊怎么办?

    2022年1月29日
    51
  • Vue学习之按键修饰符

    Vue学习之按键修饰符Vue学习之按键修饰符

    2022年4月23日
    96
  • 流式布局 简单_CSS3流式布局

    流式布局 简单_CSS3流式布局第三方库://依赖:compile’com.hyman:flowlayout-lib:1.1.2’布局文件<com.zhy.view.flowlayout.TagFlowLayoutandroid:id="@+id/id_flowlayout"zhy:max_select="-1"android:layout

    2025年7月7日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号