Why NOT Use My Index

2311人阅读 评论(0) 收藏 举报
为什么定义了索引,执行时却没有用到? 可能的几种情况:


SQL> show parameter optimizer_mode
NAME                                        TYPE        VALUE
------------------------------------ ----------- ------------------------------
optimizer_mode                         string       ALL_ROWS
关于optimizer_mode参数的解释可以参考:The Oracle SQL Optimizers

3.复合索引(Concatenated Indexes)中的前导列没有作为查询条件

推荐阅读:Concatenated Indexes

4.条件列包含函数但没有创建函数索引(Function-Based Indexes)
一般来讲,Where子句中使用了函数,即使列上有索引,也不会使用到。8i后引入了Function-Based Indexes,可以解决函数列用不到索引的问题。


B*TREE Indexes improve the performance of queries that select a small percentage of rows from a table. As a general guideline, we should create indexes on tables that are often queried for less than 15% of the table's rows. This value may be higher in situations where all data can be retrieved from an index, or where the indexed columns can be used for joining to other tables.

The ratio of the number of distinct values in the indexed column / columns to the number of records in the table represents the selectivity of an index. The ideal selectivity is 1. Such a selectivity can be reached only by unique indexes on NOT NULL columns.

Example with good Selectivity

A table having 100'000 records and one of its indexed column has 88000 distinct values, then the selectivity of this index is 88'000 / 10'0000 = 0.88.

Oracle implicitly creates indexes on the columns of all unique and primary keys that you define with integrity constraints. These indexes are the most selective and the most effective in optimizing performance. The selectivity of an index is the percentage of rows in a table having the same value for the indexed column. An index's selectivity is good if few rows have the same value.

Example with bad Selectivity

lf an index on a table of 100'000 records had only 500 distinct values, then the index's selectivity is 500 / 100'000 = 0.005 and in this case a query which uses the limitation of such an index will retum 100'000 / 500 = 200 records for each distinct value. It is evident that a full table scan is more efficient as using such an index where much more I/O is needed to scan repeatedly the index and the table.




为什么Pascal不是我最喜欢的程序设计语言 Why Pascal is Not My Favorite Programming Language Brian W. Kernighan, April 2, 1981 AT&T Bell Laboratories,  Mur
  • ljljlj
  • ljljlj
  • 2011-10-01 22:00
  • 2564

Why Isn't Oracle Using My Index?!

The question in the title of this piece is probably the single most  frequently occurring question that appears in the Metalink forums and U
  • Darwin000
  • Darwin000
  • 2011-08-28 15:16
  • 228

使用use index优化sql查询

参考:http://www.cnblogs.com/edwardlost/archive/2010/12/31/1923105.html 先看一下arena_match_index的表结构,大家注意表的索引结构 CREATE TABLE `arena_match_index` ( ...
  • wzm112
  • wzm112
  • 2013-08-24 18:40
  • 527

Why do we use n = 16 * n + hexdigit

Go to my personal blog There is a program to convert a string of hexadecimal digits into its equivalent integer value as below. enum loop {NO, YES};...
  • gcvdsvb
  • gcvdsvb
  • 2015-03-28 16:39
  • 682

为什么使用 fftshift(fft(fftshift(x))) 而不是 fft(x)

详细请查阅《Why use fftshift(fft(fftshift(x))) instead of fft(x) in Matlab?》 使用fftshift(fft(fftshift(x)))后的效果: 1.不改变频谱的幅度和相位
  • u014357799
  • u014357799
  • 2017-07-23 16:04
  • 1024


201.Why does performance degrade when many UPDATE, INSERT or DELETE statements are issued  on a table that has an associated bitmap index?  ...
  • rlhua
  • rlhua
  • 2013-11-26 15:32
  • 10614

Why 分库分表 & Why Use Mycat

永久链接: http://gaojingsong.iteye.com/blog/2339126 预览文章: Why 分库分表 & Why Use Mycat  在互联网时代,海量数据的存储与访问成为系统设计与使用的瓶颈问题,对于海量数据处理...
  • gaojingsong
  • gaojingsong
  • 2016-11-20 20:23
  • 371

NoSQL Databases, why we should use, and which one we should choose

Introduction In the last years, relational databases have been the only option when we talk about data persistence. Our unique choice have been whi...
  • shuipinglp
  • shuipinglp
  • 2014-03-18 19:39
  • 464

.net Remoting用TCP和HTTP区别(下)

2010年04月04日 星期日 11:08详细说明AAA:调用进程Activator的CreateInstance()方法。这个方法将创建方法参数指定类型的类对 象。它与前面的GetObject() 不同的是,它要在客户端调用构造函数,而GetObject()只是获得对象,而创建实例是在服务...
  • flywkk1218
  • flywkk1218
  • 2010-12-29 14:59
  • 971


FORCE INDEX 通常用来对查询强制使用一个或者多个索引。 MySQL 通常会根据统计信息选择正确的索引,但是当查询优化器选择了错误的索引或者根本没有使用索引的时候,这个提示将非常有用。IGNORE INDEX 提示会禁止查询优化器使用指定的索引。在具有多个索引的查询时,可以用来指定不需要优化...
  • wangyi1015
  • wangyi1015
  • 2009-03-10 14:08
  • 1363
    • 访问:4797241次
    • 积分:51385
    • 等级:
    • 排名:第66名
    • 原创:907篇
    • 转载:54篇
    • 译文:5篇
    • 评论:348条