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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 中科大EPC课程爬取-带步骤[通俗易懂]

    中科大EPC课程爬取-带步骤[通俗易懂]原文取自木华生的帖子https://blog.csdn.net/qq_28491207/article/details/84261732原文取自木华生的帖子https://blog.csdn.n

    2022年8月1日
    8
  • linux系统查看版本命令,Linux系统查看系统版本命令[通俗易懂]

    linux系统查看版本命令,Linux系统查看系统版本命令[通俗易懂]以下操作在centos系统上实现,有些方式可能只适用centos/redhat版本系统uname-a|uname-r查看内核版本信息[root@node1~]#uname-aLinuxnode12.6.32-573.el6.x86_64#1SMPThuJul2315:44:03UTC2015x86_64x86_64x86_64GNU/Linux[root@n…

    2022年8月21日
    15
  • java输入数组元素_java数组的输出

    java输入数组元素_java数组的输出1.简介Java中快捷输出数组中各个元素笔者目前所知的就三种方法,今天就简单的做个记录。大家如果有什么更好的方法,麻烦留言评论。2.代码publicclassArrayPrint{publicstaticvoidmain(String[]args){int[]arrays1=newint[]{1,2,3,4};//ThefirstmethodSystem.out…

    2022年8月31日
    4
  • RealPlayer 11 简体中文最新正式版下载[通俗易懂]

    RealPlayer 11 简体中文最新正式版下载[通俗易懂]RealNetworks推出了新的RealPlayer11版本。支持播放在各种在线媒体视频,包括Flash,FLV格式或者MOV格式等等,并且在播放过程中能够录制视频。同时还加入了在线视频的一键下

    2022年7月3日
    31
  • XSRF 防御「建议收藏」

    XSRF 防御「建议收藏」#XSRF防御#需求分析XSRF又名CSRF(opensnewwindow),跨站请求伪造,它是前端常见的一种攻击方式,我们先通过一张图来认识它的攻击手段。CSRF的防御手段有很多,比如验证请求的referer,但是referer也是可以伪造的,所以杜绝此类攻击的一种方式是服务器端要求每次请求都包含一个token,这个token不在前端生成,而是在我们每次访…

    2022年5月19日
    32
  • 跨平台数据整合系统_lvc异构系统

    跨平台数据整合系统_lvc异构系统1.muleESB整合系统四种模式A.简单服务模式属于几个webService之间的同步调用,请求响应处理模式。B.桥接模式C.校验器模式校验器模式通过定义一个校验过滤器过滤服务请求,并同步返回

    2022年8月2日
    10

发表回复

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

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