`
sjk2013
  • 浏览: 2191639 次
文章分类
社区版块
存档分类
最新评论

oracle virtual index

 
阅读更多
虚拟索引不消耗CPU以及IO,还有存储空间,用来判断创建的索引是否可被用,下面举例说明:
SQL> create table tb1 as select owner,object_name,object_id from dba_objects; --创建测试表

Table created.

SQL> select count(*) from tb1;

COUNT(*)
----------
50518

SQL> explain plan for select * from tb1 where object_id=108;

Explained.

SQL> select * from table(dbms_xplan.display); ---未创建虚拟索引前的执行计划

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3226679318

--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 384 | 78 (2)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TB1 | 4 | 384 | 78 (2)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------

1 - filter("OBJECT_ID"=108)

Note
-----
- dynamic sampling used for this statement

17 rows selected.

SQL> alter session set "_use_nosegment_indexes"=true; --修改相关参数

Session altered.

SQL> create index tb1_object_id_idx on tb1(object_id) nosegment; --创建虚拟索引

Index created.

SQL> explain plan for select * from tb1 where object_id=108; --创建虚拟索引侯的执行计划

Explained.

SQL> select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 959502086

-------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 384 | 5 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| TB1 | 4 | 384 | 5 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | TB1_OBJECT_ID_IDX | 219 | | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------

2 - access("OBJECT_ID"=108)

Note
-----
- dynamic sampling used for this statement

18 rows selected.

注意:此索引在dba_indexes中是无法查到的,需要查询dba_ind_columns
SQL> create index TB1_OBJECT_ID_IDX on tb1(object_id); --虽然是虚拟索引,但是还是不能创建同名的索引,需要删除改虚拟索引 --创建真实索引
create index TB1_OBJECT_ID_IDX on tb1(object_id)
*
ERROR at line 1:
ORA-00955: name is already used by an existing object

SQL> select index_owner,index_name from dba_ind_columns where lower(index_name)='tb1_object_id_idx';

INDEX_OWNER INDEX_NAME
------------------------------ ------------------------------
SYS TB1_OBJECT_ID_IDX

SQL> drop index tb1_object_id_idx; ---找出并删除该虚拟索引

Index dropped.
分享到:
评论

相关推荐

    Oracle.RMAN.11g.Backup.and.Recovery.2010(Oracle RMAN 11g 备份和恢复)

    Manage physical and virtual media with Oracle Secure Backup Work with Oracle RMAN catalogs, packages, and control files Use the Amazon Web Services cloud as an offsite storage solution Create on...

    oracle 批量删除表数据的几种方法

     删除PRIMARY_INDEX_TEST表中,MINDEX_ID字段为空的数据  情景二:  删除VIRTUAL_CARD_TEST表中的脏数据 2.解决方案  情景一的解决方案:  DELETE FROM PRIMARY_INDEX_TEST WHERE MINDEX_ID IS NULL  情景...

    Oracle使用游标进行分批次更新数据的6种方式及速度比对

    1.情景展示  一共有22w条数据, 需要将A表的主键更新至B表的指定字段,如何快速完成更新? 2.解决方案  声明:  解决方案不只一种,该文章只介绍快速游标... FROM VIRTUAL_CARD10 T1, PRIMARY_INDEX10 T2  WHERE

    Mac OS 配置Java开发环境

    1.1 官网下载JDK安装文件 https://www.oracle.com/technetwork/java/javase/downloads/index.html 1.2 下载系统对应的版本并安装JDK  我安装的是1.8版本 二:配置Java环境变量 a: 打开终端,输入 open ~/.bash_...

    Delphi最新三层源码

    主要功能就是把数据存储隐藏起来,调用SQL, ORACLE,之类。我主要是用它调用数据库工厂创建。 大致看一下代码吧。 //----------//1.工厂基类(SQLServer工厂类)//----------unit ConnDBFactory_SQLServer;...

    MySQL and JSON A Practical Programming Guide 2018

    Written by a MySQL Community Manager for Oracle, MySQL and JSON: A Practical Programming Guide shows how to quickly get started using JSON with MySQL and clearly explains the latest tools and ...

    Progress/OpenEdge语言手册

    * An index of ABL keywords. Using this manual OpenEdge provides a special purpose programming language for building business applications. In the documentation, the formal name for this language is ...

    Javashop开发规范V2.2

    xml Mysql Oracle SqlServer int int NUMBER smallint int(1) smallint(1) NUMBER(2) int memo text CLOB text datetime datetime TIMESTAMP datetime long bigint NUMBER bigint decimal decimal NUMBER(20,2) ...

    测试培训教材

    QC支持的数据库:Oracle、SQLServer QC支持的操作系统:Windows、Linux、Solaris 支持群集: 服务器端硬件和数据库要求: Windows: Linux: Solaris: 客户端系统要求: 练习1:安装QC 详见...

    php.ini-development

    ;;;;;;;;... 1.... 2.... 3.... 4.... 5.... 6.... The syntax of the file is extremely simple.... Section headers (e.g.... at runtime.... There is no name validation.... (e.g.... previously set variable or directive (e.g....

Global site tag (gtag.js) - Google Analytics