ORA FAQ 性能调整系列之——压缩索引会提高性能么?

索引|性能|压缩

Will compressing my indexes improve performance ?
压缩索引会提高性能么?

Author's name: Jonathan Lewis

Author's Email: Jonathan@jlcomp.demon.co.uk
 Date written: 26th Feb 2003

Oracle version(s): 8.1 - 9.2

Compressed indexes have been around for a couple of years now - but will compressing your indexes automatically improve performance ?
压缩索引已经存在好几年了——那么压缩索引会自动提高性能么?

Oracle introduced a compression option for indexes in Oracle 8.1. You can create an index as compressed, or rebuild it to compress it (although there are some restrictions about online rebuilds, rebuilds of partitioned indexes etc.) Typical syntax might be:
Oracle在Oracle 8.1中引入了索引的压缩特性。你可以创建一个压缩索引,或者重建时压缩一个索引(尽管对在线重建、重建分区索引等有一些限制)。标准语法如下:

 create index t1_ci_1 on t1(col1, col2, col3, col4) compress 2;

 alter index t1_ci_1 rebuild compress 2;

The benefits of compression come from the fact that a properly compressed index uses a smaller number of leaf blocks - which tends to mean that less I/O is involved when the index is used, there is a reduced amount of buffer cache flushing, and the optimizer is likely to calculate a lower cost for using that index for range scans. (There is a tiny chance that the number of branch blocks, and the index height might be reduced, too, but that is a little unlikely).
压缩的优势来自一个恰当压缩的索引使用更少的叶块——这样当用到索引时涉及更少的I/O,buffer cache清洗量减小,优化器对index range scan代价的计算可能更低。(甚至有机会分支块数与索引高度也会减少,但这不太可能)。

But compressing indexes, especially compressing the wrong number of columns, can have negative impact on your performance. If you compress more columns than you should, the 'compressed' index may be larger than the uncompressed index. Use the validate option on the index, and check view index_stats to find out the optimum compression count. How did I know that I should compress just the first two columns of the t1_ci_1 index ? (Apart from knowing the data, that is):
但压缩索引,特别是压缩烈数不正确时,会对性能产生负面影响。如果压缩了过多的列,“压缩”了的索引可能比未压缩的索引更大。对索引使用validate选项,然后检查视图index_stats找到最优的压缩数。我如何知道只需要压缩索引t1_ci_1的前两列?(不需要知道数据):

 validate index t1_ci_1;

 select
 opt_cmpt_count, opt_cmpr_pctsave
 from
 index_stats;

 opt_cmpt_count opt_cmpr_pctsave
 -------------------------------
              2               50

Unfortunately these two columns don't exist in 8.1, only in version 9 (possibly only 9.2). Fortunately Steve Adams has a script on his website to recommend a compression level (see www.ixora.com.au )
不幸的是这两列在8.1中不存在,只存在于9(可能仅仅9.2)。幸运的是Steve Adams在他的站点上有一个脚本以推荐压缩度(参考www.ixora.com.au)

Even if you get the 'right' number of columns compressed, there is a price to pay: The main penalties are: (a) reads and mods of a compressed index cost more CPU than they would (typically) for an equivalent uncompressed index (b) execution paths change - and you may not have predicted the changes, and some nominally cheaper paths may actually be slower. for example: Oracle may choose an index fast full scan instead of an index range scan because the compressed index is now much smaller, and your setting for parameter db_file_multiblock_read_count is large; or Oracle may choose to use an index and do a nested loop because the index is now 30% smaller, where previously it was doing a table scan and hash join.
即使你得到了压缩列的“正确”数字,还有一个代价:主要的性能损失是:(a)读、改一个压缩索引比一个同等的未压缩索引消耗更多的CPU;(b)执行路径改变——并且你可能没有意识到这个改变,一些看似代价更低的路径可能反而慢。例如:由于压缩索引现在更小了,对参数db_file_multiblock_read_count也较大,那么Oracle可能选择一个index fast full scan而不是index range scan;或者由于索引减小了30%,Oracle选择使用一个索引和nested loop,而之前它用表扫描和hash join。

So - don't go and compress all the indexes in your schema.
所以——不要压缩所有索引。

Think carefully about which indexes could give you significant gains, and whether you can afford some CPU loss to reduce buffer thrashing and I/O.
想好那个索引会给你较大的性能提高,你是否能够承受一些CPU损耗来降低buffer清洗和I/O。

Remember too, if the way you use an index is such that the column order doesn't matter, then perhaps you could rearrange the column order to maximise the compression. The most critical point, perhaps, is that you should avoid moving a column that is typically used with a range scan towards the front of the index.t
还要记住,若你使用索引时并不在意列的顺序,那么也许你可以重新安排列的顺序来提高压缩率。最关键的一点也许是你应当避免向索引前移一个一般用来range scan的列。

--------------------------------------------------------------------------------
本文翻译自http://www.jlcomp.demon.co.uk/faq/  译者仅保留翻译版权

时间: 2024-08-03 08:52:21

ORA FAQ 性能调整系列之——压缩索引会提高性能么?的相关文章

ORA FAQ 性能调整系列之——当索引第一列由序列产生,一个逆序索引有什么用?

索引|性能 ORA FAQ 性能调整系列之--The Oracle (tm) Users' Co-Operative FAQWhy would a reverse index be useful when the leading column of the index is generated from a sequence ?当索引第一列由序列产生,一个逆序索引有什么用?--------------------------------------------------------------

第十章——维护索引(7)——使用索引视图提高性能

原文:第十章--维护索引(7)--使用索引视图提高性能 前言: 视图是一个包含了一个或多个表的数据列的虚拟表.通常情况下,它仅仅是存储了查询的对象,一个视图可以当作一个表,可以用于存储过程.JOIN.用户自定义函数等等. 视图包含了下面两个主要特性: 1. 提供了一个安全机制,用于限制用户只能访问特定的数据. 2. 使得开发人员能定制用户的逻辑视图.   当你查询一个视图时,优化器会产生一个单一的执行计划给这个查询.在索引视图未出现之前,视图必须解决查询在执行期间才硬化.所有的JOIN.聚合都在

ORA FAQ 性能调整系列之——Oracle 9与Oracle 8中CPU

oracle|性能 What is the difference between cpu_costing in Oracle 9 and the old costing of Oracle 8 ?Oracle 9与Oracle 8中CPU_COSTING有什么变化? Author's name: Jonathan LewisAuthor's Email: Jonathan@jlcomp.demon.co.ukDate written: 15th Dec 2002 Oracle version(s

用 SQL Server 2000 索引视图提高性能

server|视图|索引|性能 什么是索引视图? 许多年来,Microsoft SQL Server 一直都提供创建虚拟表(称为视图)的功能.在过去,这些视图主要有两种用途: 提供安全机制,将用户限制在一个或多个基表中的数据的某个子集. 提供一种机制,允许开发人员定制用户如何才能以逻辑方式查看存储在基表中的数据. SQL Server 2000 已经扩展了 SQL Server 视图的功能,以提高系统性能.它可以在一个视图上创建唯一的群集索引和非群集索引,可以改进最复杂查询的数据访问性能.在 S

通过 SQL Server 2005 索引视图提高性能

本文介绍了 SQL Server 2005 Enterprise Edition 中经过改进的索引视图功能.文中对索引视图进行了说明介绍,并讨论了可通过该功能改善性能的一些具体情况 一.索引视图 多年以来,Microsoft SQL Server 一直支持创建称为视图的虚拟表.通常,这些视图的主要作用是: • 提供一种安全机制,将用户限制到一个或多个基表的某个数据子集中. • 提供一种机制,允许开发人员自定义用户通过逻辑方式查看存储在基表中的数据的方式. 通过 SQL Server 2000,S

用SQL Server 2005索引视图提高性能一

一.索引视图 多年以来,MicrosoftSQL Server一直支持创建称为视图的虚拟表.通常,这些视图的主要作用是: 提供一种安全机制,将用户限制到一个或多个基表的某个数据子集中. 提供一种机制,允许开发人员自定义用户通过逻辑方式查看存储在基表中的数据的方式. 通过 SQL Server 2000,SQL Server 视图的功能得到了扩展,实现了系统性能方面的收益.可在视图上创建唯一的聚集索引及非聚集索引,来提高最复杂的查询的数据访问性能.在 SQL Server 2000 和 2005

使用SQL Server 2000索引视图提高性能

本文介绍 SQL Server 2000 企业版的新功能 - 索引视图.讲解索引视图并讨论一些提高性能的具体方案. 什么是索引视图? 许多年来,Microsoft SQL Server 一直都提供创建虚拟表(称为视图)的功能.在过去,这些视图主要有两种用途: 提供安全机制,将用户限制在一个或多个基表中的数据的某个子集. 提供一种机制,允许开发人员定制用户如何才能以逻辑方式查看存储在基表中的数据. SQL Server 2000 已经扩展了 SQL Server 视图的功能,以提高系统性能.它可以

NetApp性能调优:如何不加磁盘提高性能

    Tech OnTap 的读者可能大多都知道,存储系统的随机读取性能在很大程度上取决于硬盘数(存储系统中的硬盘总数)和硬盘转速(单位 RPM).但是,为提高性能而增加硬盘就意味着需要更多的功耗.散热及空间:而且,伴随着硬盘容量增加速度快于其性能表现的提升,很多应用程序可能为了获得最佳性能而要求增加磁盘轴,即便它们并不需要如此大的容量. 在开发性能提高模块(Performance Acceleration Module,简称 PAM)时,NetApp 的目标就是突破随机读取性能和轴数之间的联

用SQLServer2000索引视图提高性能(下)

server|sqlserver|视图|索引|性能 使用"索引微调向导" "索引微调向导"除建议使用基表的索引之外,还建议使用索引视图.使用该向导可提高管理员确定索引和索引视图相结合的能力,从而优化针对数据库执行的典型混合查询的性能. 由于"索引微调向导"强制使用所有必需的 SET 选项(以确保结果集的正确性),其索引视图将会成功创建.不过,如果您的应用程序的选项没有按照要求设置,可能无法利用这些视图.对那些参与索引视图定义的表执行的插入.更新或