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

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

    eg: 执行:perror 1064 返回:MySQL error code 1064 (ER_PARSE_ERROR): %s near '%-.80s' at line %d           ...

  2. JAVA-1-HelloWorld

    public class HelloWorld{ public static void main(String[] args){ System.out.println("HelloWorld ...

  3. QT 5.1.1 for Android 开发环境搭建与配置【Windows 7】

    前言:本人操作系统为Windows7 64位,用的是32位的安装包,32位系统没有验证. 一.首先下载以下安装包,如果提供的链接失效请自行下载: (1) Android SDK (Windows 32 ...

  4. MySql中的事务嵌套

    1.Mysql中的事务必须是InnoDB.Berkeley DB引擎,myisam不支持. 2.Mysql是不支持嵌套事务的,开启了一个事务的情况下,再开启一个事务,会隐式的提交上一个事务. 3.My ...

  5. js插件zClip实现复制到剪贴板功能

    相信这个功能大家平时上网经常能碰到,以前也没怎么留意怎么实现的,直到项目中需要. 网上一搜一大堆,单纯使用js方法也不是没有,但是由于各浏览器的安全机制不同,不是跨浏览器的.去看了几个常用的网站,都是 ...

  6. 在线提取PDF中图片和文字

    无需下载软件,你就可以在线提取PDF中图片和文字,http://www.extractpdf.com/不仅可以获取本地PDF文档的图片和文字,还能获取远程PDF文档的图片和文字.如下图所示:结果本人测 ...

  7. Symfony2 EventDispatcher组件

            一个插件系统中,A插件在不影响其它插件的前提下,添加新的方法,或者在一个方法运行前做一些准备工作,通过继承来实现扩展是很不容易的,由于插件之间的关联关系,A插件的改变也会使得关联的插件 ...

  8. Chrome下的语音控制框架MyVoix.js使用篇(四)

    在上一篇博文中,我为大家介绍了myvoix.js中的smart learning模块,以及何如使用该功能.(myvoix.js的源码地址会在每一篇文章末尾放出) 文本将拓展 Chrome下的语音控制框 ...

  9. 转:Twitter.com在用哪些Javascript框架?

    原文来自于:http://blog.jobbole.com/63964/ 我一直在研究twitter.com使用的一些UI框架.下面是这些框架的清单(大部分是Javascript框架).如果你发现有些 ...

  10. uva 10007 Count the Trees

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...