Choosing Columns and Expressions to Index
A key is a column or expression on which you can build an index. Follow these guidelines for choosing keys to index:
- Consider indexing keys that are used frequently in
WHERE
clauses. - Consider indexing keys that are used frequently to join tables in SQL statements. For more information on optimizing joins, see the section "Using Hash Clusters".
- Index keys that have high selectivity. The selectivity of an index is the percentage of rows in a table having the same value for the indexed key. An index's selectivity is optimal if few rows have the same value.
Note:Oracle automatically creates indexes, or uses existing indexes, on the keys and expressions of unique and primary keys that you define with integrity constraints.
Indexing low selectivity columns can be helpful if the data distribution is skewed so that one or two values occur much less often than other values.
- Do not use standard B-tree indexes on keys or expressions with few distinct values. Such keys or expressions usually have poor selectivity and therefore do not optimize performance unless the frequently selected key values appear less frequently than the other key values. You can use bitmap indexes effectively in such cases, unless a high concurrency OLTP application is involved where the index is modified frequently.
- Do not index columns that are modified frequently.
UPDATE
statements that modify indexed columns andINSERT
andDELETE
statements that modify indexed tables take longer than if there were no index. Such SQL statements must modify data in indexes as well as data in tables. They also generate additional undo and redo. - Do not index keys that appear only in
WHERE
clauses with functions or operators. AWHERE
clause that uses a function, other thanMIN
orMAX
, or an operator with an indexed key does not make available the access path that uses the index except with function-based indexes. - Consider indexing foreign keys of referential integrity constraints in cases in which a large number of concurrent
INSERT
,UPDATE
, andDELETE
statements access the parent and child tables. Such an index allowsUPDATE
s andDELETE
s on the parent table without share locking the child table. - When choosing to index a key, consider whether the performance gain for queries is worth the performance loss for
INSERT
s,UPDATE
s, andDELETE
s and the use of the space required to store the index. You might want to experiment by comparing the processing times of the SQL statements with and without indexes. You can measure processing time with the SQL trace facility.See Also: Oracle9i Application Developer's Guide - Fundamentals for more information on the effects of foreign keys on locking
Choosing Composite Indexes
A composite index contains more than one key column. Composite indexes can provide additional advantages over single-column indexes:
- Improved selectivity
Sometimes two or more columns or expressions, each with poor selectivity, can be combined to form a composite index with higher selectivity.
- Reduced I/O
If all columns selected by a query are in a composite index, then Oracle can return these values from the index without accessing the table.
A SQL statement can use an access path involving a composite index if the statement contains constructs that use a leading portion of the index.
Note: This is no longer the case with index skip scans. See "Index Skip Scans". |
A leading portion of an index is a set of one or more columns that were specified first and consecutively in the list of columns in the CREATE
INDEX
statement that created the index. Consider this CREATE
INDEX
statement:
CREATE INDEX comp_ind
ON table1(x, y, z);
x
,xy
, andxyz
combinations of columns are leading portions of the indexyz
,y
, andz
combinations of columns are not leading portions of the index
Choosing Keys for Composite Indexes
Follow these guidelines for choosing keys for composite indexes:
- Consider creating a composite index on keys that are used together frequently in
WHERE
clause conditions combined withAND
operators, especially if their combined selectivity is better than the selectivity of either key individually. - If several queries select the same set of keys based on one or more key values, then consider creating a composite index containing all of these keys.
Of course, consider the guidelines associated with the general performance advantages and trade-offs of indexes described in the previous sections.
Ordering Keys for Composite Indexes
Follow these guidelines for ordering keys in composite indexes:
- Create the index so the keys used in
WHERE
clauses make up a leading portion. - If some keys are used in
WHERE
clauses more frequently, then be sure to create the index so that the more frequently selected keys make up a leading portion to allow the statements that use only these keys to use the index. - If all keys are used in
WHERE
clauses equally often, then ordering these keys from most selective to least selective in theCREATE
INDEX
statement best improves query performance. - If all keys are used in the
WHERE
clauses equally often but the data is physically ordered on one of the keys, then place that key first in the composite index.
Choosing Columns and Expressions to Index的更多相关文章
- pandas-07 DataFrame修改index、columns名的方法
pandas-07 DataFrame修改index.columns名的方法 一般常用的有两个方法: 1.使用DataFrame.index = [newName],DataFrame.columns ...
- pandas的.columns和.index
可以通过.columns和.index着两个属性返回数据集的列索引和行索引 设data是pandas的一个DataFram类型的数据集. 则data.index返回一个index类型的行索引列表,da ...
- MySQL: Building the best INDEX for a given SELECT
Table of Contents The ProblemAlgorithmDigressionFirst, some examplesAlgorithm, Step 1 (WHERE "c ...
- Index on DB2 for z/OS: DB2 for z/OS 的索引
可以创建在任何表上的索引: Unique Index:An index that ensures that the value in a particular column or set of col ...
- Oracle composite index column ordering
Question: I have a SQL with multiple columns in my where clause. I know that Oracle can only choos ...
- 关于分区技术的索引 index
关于分区技术---索引 Index 一. 分区索引分类: 本地前缀分区索引(local prefixedpartitioned index) 全局分区索引(global partitionedin ...
- pandas更换index,column名称
1)仅换掉index名称 df.index = list 2)调整index时,后面的项目也要跟着调整: df.reindex(list) 注意如果list中出现了df中没有的index,后面的项目会 ...
- python. pandas(series,dataframe,index) method test
python. pandas(series,dataframe,index,reindex,csv file read and write) method test import pandas as ...
- PostgreSQL执行计划:Bitmap scan VS index only scan
之前了解过postgresql的Bitmap scan,只是粗略地了解到是通过标记数据页面来实现数据检索的,执行计划中的的Bitmap scan一些细节并不十分清楚.这里借助一个执行计划来分析bitm ...
随机推荐
- C#工具介绍
VisualStudio是微软的官方提供的.NET开发工具. 除了VisualStudio外,还有一些开源的.NET开发IDE. MonoDevelop.SharpDevelop等. 开发未必需要使用 ...
- 信号处理程序(signal handler)会被重置的信号
首先说明我的系统,CentOS 6.6,内核为2.6.32-504.12.2.el6.i686. 当用signal对某个信号设定信号处理函数的时候,有些信号的处理函数会被重置,有些则不会,这种情况的具 ...
- linux下dup/dup2函数的用法
系统调用dup和dup2能够复制文件描述符.dup返回新的文件文件描述符(没有用的文件描述符最小的编号).dup2可以让用户指定返回的文件描述符的值,如果需要,则首先接近newfd的值,他通常用来重新 ...
- 常用HTML meta 标签属性(网站兼容与优化需要),meta标签
常用HTML meta 标签属性(网站兼容与优化需要),meta标签 标签提供关于HTML文档的元数据.元数据不会显示在页面上,但是对于机器是可读的.它可用于浏览器(如何显示内容或重新加载页面),搜索 ...
- Unable to load DLL 'rasapi32.dll': 动态链接库(DLL)初始化例程失败。
今天做项目传到服务器上碰到下面的问题 但是在本地VS中运行又没问题 后经上网搜索发现只要在web.config文件中加入如下代码即可解决 <system.net> <defa ...
- 无法安装程序包“MIcrosoft.Owin.Security 2.0.2”。您正在尝试将此程序包安装到某个将“.NETFramework,Version=v4.0”作为目标的项目中。
在VS2010 MVC4项目中,安装NuGet程序包Microsoft.AspNet.SignalR时出现以下错误: 原因是安装的版本是Microsoft.AspNet.SignalR 2.0.2,要 ...
- 对图片进行各种样式裁对图片进行各种样式裁剪:圆形、星形、心形、花瓣形等剪:圆形、星形、心形、花瓣形等--第三方开源--CustomShapeImageView
CustomShapeImageView在github上的项目主页是:https://github.com/MostafaGazar/CustomShapeImageView 如果仅仅是需要获取圆形. ...
- Demo学习: Basic jQuery
UniGUI是一套基于ExtJS的Delphi的WEB框架,它是使用ExtPascal来转化到ExtJS,ExtJS是一个跨浏览器的JavaScript库,因此UniGUI发布出来的程序可以在各种浏览 ...
- php微信开发(1):缓存access_token的方法
语言:PHP access_token一直要用,但每天取的数量有限制.反正2小时才过期.就想缓存一下. File1: wx_access_token.php File2: file_cache.php ...
- linux 压缩文件 及压缩选项详解
本文介绍linux下的压缩程序tar.gzip.gunzip.bzip2.bunzip2.compress.uncompress. zip. unzip.rar.unrar等程式,以及如何使用它们对. ...