前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Oracle 11g新特性invisible index(不可见的索引)[通俗易懂]

Oracle 11g新特性invisible index(不可见的索引)[通俗易懂]

作者头像
全栈程序员站长
发布2022-07-10 10:13:40
5540
发布2022-07-10 10:13:40
举报

大家好,又见面了,我是全栈君。

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

但删除以后,假设发现某一天实用,那又要又一次建,假设是大表。那就有些麻烦。如今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.cn/115714.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年1月3,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档