Oracle composite index column ordering
Answer: You are correct that the column sequence matters! This is an empirical question, and you need to run diagnostic scripts against your SQL workload (STATSPACK or AWR) to examine how frequently a specific index column was needed by SQL. Remember, it's the SQL workload that drives your choice of composite indexes, and the order of the columns within the index.
See these important scripts to display multi-column index usage using AWR.
- In general, when using a multi-column index, you want to put the most restrictive column value first (the column with the highest unique values) because this will trim-down the result set.
- Because Oracle can only access one index, your job is to examine your historical SQL workload and build a single composite index that satisfies the majority of the SQL queries.
- The Oracle optimizer may try to make single column indexes behave as-if they were a single composite index. Prior to 10g, this could be done with the "and_equal" hint.
- Beware that indexes have overhead and see my notes on detecting duplicate index columns.
- You can run scripts to monitor the invocation count for each column in a multiple column composite index (see counting column usage from a SQL workload)
I have more complete details on composite index usage monitoring in my bookAdvanced Oracle SQL Tuning: The Definitive Reference. Also, see my related notes on tuning with composite bitmap indexes and my scripts to monitor which columns of a composite index are used, and counting index column usage from AWR and STATSPACK.
Large Multi-column Composite Indexes
Multi-column indexes with more than 3 columns may not provide more efficient access than a two-column index. The objective of the index is to reduce the amount of rows returned from a table access. Therefore each added column must substantially reduce the number of returned rows to be effective. For example, assuming a large table, on a query with 5 or more WHERE (AND) clauses using a 5-column index may return only 1 row. However using a 3-column index may return only 50 rows. A two-column index returns 200 rows. The time it takes to extract the one row from the 200 rows using nested-loops is negligible.
Thus the two-column index may be almost as efficient (fast) as the 5-column index. The key is to index the most restrictive columns. Another tradeoff is a table with multiple column indexes where the leading column(s) are the same. For instance, a table with four 3-column indexes where the leading two columns are the same may work very efficiently on select statements but cause a heavy penalty on inserts and updates. Just one 2-column index on the leading two columns may provide acceptable query performance while greatly improving DML.
Small tables with two or three columns may benefit by being rebuilt as an Index Organized Table (IOT). A 2-column table with a primary key and a two-column index has 1.5 times the data in indexes that are in the table. Making the table an Index Organized Table reduced the need for indexes because the table is the index. Also IOTs can have indexes on non-leading columns if required. Again this has to be balanced with the overhead of maintaining the IOT.
Lastly, do not be afraid to use temporary indexes. If you run a nightly report that requires 6 hours to run, but will run in 30 mins with a specific index, you might want to create the index before running the report and drop it upon completion. I work with clients that drop certain indexes to expedite the bill run, then recreate then for the normal application. They create indexes each night and drop them in the morning. There is nothing wrong with dynamically changing you database to respond to varying tasks if it results in efficiency.
Script for tracking composite index column usage
These scripts will only track SQL that you have directed Oracle to capture via your threshold settings in AWR or STATSPACK. STATSPACK and AWR will not collect "transient SQL" that did not appear in v$sql at snapshot time. Hence, not all SQL will appear in these reports. See my notes here on adjusting the SQL capture thresholds.
index_usage_hr.sql
SEE CODE DEPOT FOR FULL SCRIPTS dba_hist_snapshot sn, dba_hist_sql_plan p, dba_hist_sqlstat st where st.sql_id = p.sql_id and sn.snap_id = st.snap_id and p.object_name = ‘&idxname' group by begin_interval_time,search_columns;
The query will produce an output showing a summary count of the index specified during the snapshot interval. This can be compared to the number of times that a table was invoked from SQL. Here is a sample of the output from the script.
Invocation Counts for cust_index Begin Interval Invocation time Search Columns Count -------------------- -------------- ----------- 04-10-21 15 1 3 04-10-10 16 0 1 04-10-10 19 1 1 04-10-11 02 0 2 04-10-11 04 2 1 04-10-11 06 3 1 04-10-11 11 0 1 04-10-11 12 0 2 04-10-11 13 2 1 04-10-11 15 0 3 04-10-11 17 0 14 04-10-11 18 4 1 04-10-11 19 0 1 04-10-11 20 3 7 04-10-11 21 0 1Oracle composite index column ordering的更多相关文章
- Oracle 字段监控 ( column monitor)
Oracle 字段监控 ( column monitor) */--> Oracle 字段监控 ( column monitor) Table of Contents 1. 开启与关闭 2. 字 ...
- mysql 1709: Index column size too large. The maximum column size is 767 bytes.
1709: Index column size too large. The maximum column size is 767 bytes. 修改排序规则解决 utf8_general_ci
- Index column size too large. The maximum column size is 767 bytes.
mysql建表时报Index column size too large. The maximum column size is 767 bytes.解决办法:在建表语句的后面加入:ENGINE=In ...
- JanusGraph 创建索引步骤(composite index)踩坑总结
前言 JanusGraph是一个图数据库引擎,安装及入门可以参考 JanusGraph 图数据库安装小记.为了提高查询速度,在使用过程中一般要为某些属性创建索引.这篇随笔主要是记录创建索引过程中踩过的 ...
- Oracle(创建index)
概念: 1. 类似书的目录结构 2. Oracle 的“索引”对象,与表关联的可选对象,提高SQL查询语句的速度 3. 索引直接指向包含所查询值的行的位置,减少磁盘I/O 4. 与所索引的表是相互独立 ...
- Oracle alter index rebuild 与 ORA-08104 说明
在ITPUB 论坛上看到的一个帖子,很不错.根据论坛的帖子重做整理了一下. 原文链接如下: alter index rebuild online引发的血案 http://www.itpub.net/t ...
- oracle alter index rebuild offline与online
oracle index build online与offline测试环境为oracle 11.2.0.4 --sql test SQL> conn test/test )); begin .. ...
- Oracle 11G INDEX FULL SCAN 和 INDEX FAST FULL SCAN 对比分析
SQL> drop table test; 表已删除. SQL> create table test as select * from dba_objects where 1!=1; 表已 ...
- Oracle 索引 index
索引是一个模式对象,其中包含每个值的条目,该条目出现在表或集群的索引列中,并提供对行的直接快速访问. 创建一个索引: create index 索引名 on 表名 (字段名); 删除索引: dro ...
随机推荐
- JavaScript中Array的一些实用操作技巧
最近在调试JSP页面时频繁与ajax打交道,在复杂场景下,ajax传参数就需要对大量参数进行处理.这时我才发现,熟练Array的处理真的会使开发轻松不少!! 关于Array Array的创建很灵活,可 ...
- 11个优秀的HTML5 & CSS3下拉菜单制作教程
下拉菜单是一个很常见的效果,在网站设计中被广泛使用.通过使用下拉菜单,设计者不仅可以在网站设计中营造出色的视觉吸引力,但也可以为网站提供了一个有效的导航方案.使用HTML5和CSS3可以更容易创造视觉 ...
- hdu 1874 畅通工程续 Dijkstra
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1874 题目分析:输入起点和终点,顶点的个数,已连通的边. 输出起点到终点的最短路径,若不存在,输出-1 ...
- Codevs 1003 电话连线
时间限制: 1 s 空间限制: 128000 K 题目等级 : 黄金 Gold 题目描述 Description 一个国家有n个城市.若干个城市之间有电话线连接,现在要增加m条电话线(电话线当 ...
- 在Java中怎样把数组转换为ArrayList?
翻译自:How to Convert Array to ArrayList in Java? 本文分析了Stack Overflow上最热门的的一个问题的答案,提问者获得了很多声望点,使得他得到了在S ...
- 《LDAP服务器的配置与客户端的测试》RHEL6——第一篇 运维工程师必考
ldap这种原始的服务器搭建起来比较复杂,同时它也是CE必考的(客户端的搭建). 服务器端的配置: 1.安装openldap-servers软件包 2.查看ldap模板文件的存放位置: 3.拷贝lda ...
- Matlab2012a第一次安装打不开 查找程序安装类时出错
打开bin文件夹下的matlab!!!!!!进行激活~
- [转]Android在eclipse中的快捷键
1.选中你要加注释的区域,用ctrl+shift+C 会加上//注释2.先把你要注释的东西选中,用shit+ctrl+/ 会加上/* */注释3.要修改在eclispe中的命令的快捷键方式我们只 ...
- Stanford parser:入门使用
一.stanford parser是什么? stanford parser是stanford nlp小组提供的一系列工具之一,能够用来完成语法分析任务.支持英文.中文.德文.法文.阿拉伯文等多种语言. ...
- 2013-07-26 IT 要闻速记快想
### ========================= ###传Google正在内测供用户买卖技能的电商平台Helpout,最早于下月上线该服务将依托Google强大的云服务和搜索能力,以实时视频 ...