[原创]虚拟索引在生产环境中的使用_MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2601 | 回复: 0   主题: [原创]虚拟索引在生产环境中的使用        下一篇 
xiaogang.xu
注册用户
等级:上士
经验:251
发帖:13
精华:0
注册:1970-1-1
状态:离线
发送短消息息给xiaogang.xu 加好友    发送短消息息给xiaogang.xu 发消息
发表于: IP:您无权察看 2016-8-10 17:26:18 | [全部帖] [楼主帖] 楼主

一、背景

在生产环境上,经常会出现一些生产环境有而测试环境没有的性能问题,而这些性能问题可能是由于某条语句性能差导致的,索引通常是优化SQL的很好手段,但是在生产环境任何的DDL操作都应该谨慎,创建没加online的索引时,会对该对象的DML操作产生阻塞。这是我们假象,如果这张表有这个索引,那又会生成什么样的执行计划,这就是虚拟索引的用处。

适用:OACLE 11G及以后的版本

 

二、虚拟索引概念

虚拟索引指没有创建对应的物理实体的索引,虚拟索引的目的,是在不耗时、CPUIO、大量存储空间去实际创建索引的情况下,来判断一个索引是否能够对SQL优化起到作用。nosegment选项表明索引是虚拟的,_use_nosegment_indexes指示数据库可以在执行计划中使用虚拟索引。

 

三、示例 

SQL> create table temp_123 as select * from user_objects;

表已创建。

SQL> explain plan for select * from temp_123 where object_id=1630654;

已解释。

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

PLAN_TABLE_OUTPUT                                                               

--------------------------------------------------------------------------------

Plan hash value: 3542478759                                                     

                                                                                

------------------------------------------------------------------------------  

| Id  | Operation         | Name     | Rows  | Bytes | Cost (%CPU)| Time     |  

------------------------------------------------------------------------------  

|   0 | SELECT STATEMENT  |          |    10 |  1600 |   315   (1)| 00:00:05 |  

|*  1 |  TABLE ACCESS FULL| TEMP_123 |    10 |  1600 |   315   (1)| 00:00:05 |  

------------------------------------------------------------------------------  

                                                                                

Predicate Information (identified by operation id):                             

---------------------------------------------------                             

PLAN_TABLE_OUTPUT                                                               

--------------------------------------------------------------------------------

                                                                                

   1 - filter("OBJECT_ID"=1630654)                                              

                                                                                

Note                                                                            

-----                                                                           

   - 'PLAN_TABLE' is old version                                                

   - dynamic sampling used for this statement                                   

已选择18行。

SQL> alter session set "_use_nosegment_indexes"=true;

会话已更改。

SQL> create index idx_temp on temp_123(object_id) nosegment;

索引已创建。

SQL> explain plan for select * from temp_123 where object_id=1630654;

已解释。

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

PLAN_TABLE_OUTPUT                                                               

--------------------------------------------------------------------------------

Plan hash value: 4276853690                                                     

                                                                                

--------------------------------------------------------------------------------

--------                                                                        

                                                                                

| Id  | Operation                   | Name     | Rows  | Bytes | Cost (%CPU)| Ti

me     |                                                                        

                                                                                

--------------------------------------------------------------------------------

--------                                                                        

                                                                                

PLAN_TABLE_OUTPUT                                                               

--------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |          |    10 |  1600 |     5   (0)| 00

:00:01 |                                                                        

                                                                                

|   1 |  TABLE ACCESS BY INDEX ROWID| TEMP_123 |    10 |  1600 |     5   (0)| 00

:00:01 |                                                                        

                                                                                

|*  2 |   INDEX RANGE SCAN          | IDX_TEMP |   626 |       |     1   (0)| 00

:00:01 |                                                                        

                                                                                

--------------------------------------------------------------------------------

--------                                                                        

PLAN_TABLE_OUTPUT                                                               

--------------------------------------------------------------------------------

                                                                                

                                                                                

Predicate Information (identified by operation id):                             

---------------------------------------------------                             

                                                                                

   2 - access("OBJECT_ID"=1630654)                                              

                                                                                

Note                                                                            

-----                                                                           

   - 'PLAN_TABLE' is old version                                                

   - dynamic sampling used for this statement                                   

已选择19行。

SQL> SELECT * FROM USER_INDEXES WHERE INDEX_NAME='IDX_TEMP';

未选定行

 





赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论