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

但删除以后,假设发现某一天实用,那又要又一次建,假设是大表。那就有些麻烦。如今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

Oracle 11g新特性invisible index(不可见的索引)的更多相关文章

  1. Oracle 11g 新特性 --SQL Plan Management 说明

    Oracle 11g 新特性 --SQL Plan Management 说明 参见大神博主文章: http://blog.csdn.net/tianlesoftware/article/detail ...

  2. Oracle 11g 新特性 – HM(Hang Manager)简介

    在这篇文章中我们会对oracle 11g 新特性—hang 管理器(Hang Manager) 进行介绍.我们需要说明,HM 只在RAC 数据库中存在. 在我们诊断数据库问题的时候,经常会遇到一些数据 ...

  3. 使用Oracle 11g新特性 Active Database Duplication 搭建Dataguard环境

    Duplication Database 介绍 Duplicate database可以按照用途分为2种: duplicate database(复制出一个数据库) duplicate standby ...

  4. Oracle 11g新特性

    文章转自网络 Oracle 11g于2007年7月11日美国东部时间11时(北京时间11日22时)正式发布,11g是甲骨文公司30年来发布的最重要的数据库版本,根据用户的需求实现了信息生命周期管理(I ...

  5. Oracle 11g 新特性(一)-- 虚拟列

    数据库版本: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Oracle11g 增加了虚拟列的新特性, 具体说明如 ...

  6. Oracle 11g新特性延迟段创建和truncate的增强

    下面测试Oracle 11g开始的新特性truncate的增强和延迟段空间创建. Oracle从11g开始,当用户创建一张空表的时候不会先分配段和空间,只有当对这张表插入第一行数据的时候才分配段和空间 ...

  7. Oracle 11g新特性 -- 延迟段

    11gR2之前的版本中,当创建一张表时,会自动分配段空间,这样做有几个弊端: 1. 初始创建表时就需要分配空间,自然会占用一些时间,如果初始化多张表,这种影响就被放大. 2. 如果很多表开始的一段时间 ...

  8. Oracle 11g新特性 Interval Partition

    分区(Partition)一直是Oracle数据库引以为傲的一项技术,正是分区的存在让Oracle高效的处理海量数据成为可能,在Oracle 11g中,分区技术在易用性和可扩展性上再次得到了增强.在1 ...

  9. Oracle 11g 新特性 -- Oracle Restart 说明(转载)

    转载:http://blog.csdn.net/tianlesoftware/article/details/8435670 一.  OHASD 说明 Oracle 的Restart 特性是Oracl ...

随机推荐

  1. SQL 查询字段为值不为空

      方法一sql="select   *   from   table   where   id<>null   "     or   sql="select ...

  2. 星座物语APP

    效果图: 这里的后台管理用的是duducat,大家可以去百度看说明.图片,文字都在duducat后台服务器上,可以自己修改的.(PS:图片这里是随便找的) http://www.duducat.com ...

  3. eclipse在当前项目里面批量替换所有单词

    ctrl+f里面只能单个文件用,要整个项目批量替换. 1. 先选中你要替换字符串, 2. 再菜单栏中找到Search→Text→Project,这样就会在整个项目中查找单词. 3. 然后在Search ...

  4. PHPCMS V9网站更换域名的方法

    网站在发展的过程中,很可能多次的修改域名.那么在phpcms v9中我们要怎么进行设置呢? 请进行以下步骤的修改: 1.修改/caches/configs/system.php里面所有和域名有关的,把 ...

  5. OpenStack JEOS 镜像

    JEOS:Just Enough Operating System 维基百科地址:http://en.wikipedia.org/wiki/Just_enough_operating_system O ...

  6. 图的建立——邻接矩阵表示(C语言+VC6.0平台)

    图的邻接矩阵表示及其建立(无向图) #include <stdio.h> #include <stdlib.h> typedef char VertexType;        ...

  7. Codeforces 704D Captain America

    题意:平面上有n个点,每个点必须涂成红色和蓝色中的一种,花费各为r和b(对所有的点花费都一样).m条限制,每条限制形如"y=b这条直线上两种颜色的点的数目之差的绝对值不能超过c"或 ...

  8. Android实现三级联动下拉框 下拉列表spinner

    Android实现(省.市.县)三级联动下拉框 下拉列表spinner 转载请注明出处: http://www.goteny.com/articles/2013/11/46.html http://w ...

  9. 摇滚吧HTML5!有声前端交互!(Hello, Jsonic!)

    软件工程师们摆弄1和0编写他们的乌托邦,音乐人门把玩12平均律上的音符构筑他们的伊甸园.最近,我偶然看了<蓝色骨头>这部电影,片中的男主角是位黑客,同时又兼具音乐创作的才华.在现实生活中, ...

  10. New ipad安装Perl支持安装nikto

    Title:New ipad安装Perl支持安装nikto --2012-11-15 09:47 New Ipad 越了后. ssh new ipad 进入目录 cd /tmp 下载Key文件 wge ...