您好,欢迎访问一九零五行业门户网

Oracle索引重建到底会提高多少性能?

工作中往往会观察到索引重建带来的空间释放和应用性能提升。空间释放比较容易理解,也非常容易度量,那么索引重建到底会对应用的
工作中往往会观察到索引重建带来的空间释放和应用性能提升。空间释放比较容易理解,也非常容易度量,那么索引重建到底会对应用的性能有多少影响那?首先我们会问:索引重建为什么会带来性能的提升?毫无疑问,这是因为索引重建后,与索引有关的io操作得到了降低。那么,索引io的降低在多大程度上影响了应用语句的执行效率?这恐怕需要具体问题具体分析了。
首先,我们来看一下多数情况下,索引重建的效果如何
sql> create table t1 as select rownum rn,dbms_random.string('u',20) name1,dbms_random.string('u',15) name2 from dual connect by level
表已创建。
sql> create index i1 on t1(rn);
索引已创建。
sql> analyze index i1 validate structure;
索引已分析
sql> select height,lf_rows,del_lf_rows,lf_blks,del_lf_rows btree_space,used_space,pct_used from index_stats;
    height    lf_rows del_lf_rows    lf_blks btree_space used_space  pct_used
---------- ---------- ----------- ---------- ----------- ---------- ----------
  3    999999  0 2226        0  16006445    90
sql> delete from t1 where mod(rn,2) =1;
已删除500000行。
sql> commit;
提交完成。
sql> analyze index i1 validate structure;
索引已分析
sql> select height,lf_rows,del_lf_rows,lf_blks,del_lf_rows btree_space,used_space,pct_used from index_stats;
    height    lf_rows del_lf_rows    lf_blks btree_space used_space  pct_used
---------- ---------- ----------- ---------- ----------- ---------- ----------
  3    943027    443028 2226  443028  15094893    85
sql> set timing on
sql> set autotrace on
sql> select * from t1 where rn=1;
未选定行
已用时间:  00: 00: 00.00
执行计划
----------------------------------------------------------
plan hash value: 1704772559
------------------------------------------------------------------------------------
| id  | operation      | name | rows  | bytes | cost (%cpu)| time    |
------------------------------------------------------------------------------------
|  0 | select statement    |    |  1 |  4017 |  2  (0)| 00:00:01 |
|  1 |  table access by index rowid| t1  |  1 |  4017 |  2  (0)| 00:00:01 |
|*  2 |  index range scan    | i1  |  1 |    |  2  (0)| 00:00:01 |
------------------------------------------------------------------------------------
predicate information (identified by operation id):
---------------------------------------------------
  2 - access(rn=1)
note
-----
  - dynamic sampling used for this statement (level=2)
统计信息
----------------------------------------------------------
  0  recursive calls
  0  db block gets
 --  3  consistent gets
 --  3  physical reads
  0  redo size
 465  bytes sent via sql*net to client
 508  bytes received via sql*net from client
  1  sql*net roundtrips to/from client
  0  sorts (memory)
  0  sorts (disk)
  0  rows processed
sql> select * from t1 where rn=100;
 rn
----------
name1
----------------------------------------------------------------------------------------------------
name2
----------------------------------------------------------------------------------------------------
      100
iwkrromdhlnjmxvqyrhe
vptntmmujyjjqcm
已用时间:  00: 00: 00.00
执行计划
----------------------------------------------------------
plan hash value: 1704772559
------------------------------------------------------------------------------------
| id  | operation      | name | rows  | bytes | cost (%cpu)| time    |
------------------------------------------------------------------------------------
|  0 | select statement    |    |  1 |  4017 |  4  (0)| 00:00:01 |
|  1 |  table access by index rowid| t1  |  1 |  4017 |  4  (0)| 00:00:01 |
|*  2 |  index range scan    | i1  |  1 |    |  3  (0)| 00:00:01 |
------------------------------------------------------------------------------------
predicate information (identified by operation id):
---------------------------------------------------
  2 - access(rn=100)
note
-----
  - dynamic sampling used for this statement (level=2)
统计信息
----------------------------------------------------------
  0  recursive calls
  0  db block gets
 -- 5  consistent gets
 --  1  physical reads
  0  redo size
 696  bytes sent via sql*net to client
 519  bytes received via sql*net from client
  2  sql*net roundtrips to/from client
  0  sorts (memory)
  0  sorts (disk)
  1  rows processed
sql> select * from t1 where rn=1000;
其它类似信息

推荐信息