Home » RDBMS Server » Performance Tuning » Why Oracle don't use my predefined index? (Oracle 10G, windows)
Why Oracle don't use my predefined index? [message #502525] Thu, 07 April 2011 01:07 Go to next message
Tlg13team
Messages: 100
Registered: June 2008
Location: MGL
Senior Member
Hi all,

I have been meet interesting issue during the work.

Here, let me explain:

I have create a table with 8 million records and 2 different indexes using 2 different columns (columns name NUM1 & NUM2) on that table.

First indexed column (NUM1) values have many different values (1,2,3... etc).

Second indexed column (NUM2) values have only 2 different values.
7999999 records values is same("A") and remaining one record values is different("B").

Query1:
select * from tbl where num1=val

Query2:
select * from tbl where num2='B'

I have compare explain plan both queries, but Query2 doesn't use predefined index.

Why Oracle don't use my redefined index at column NUM2?
Re: Why Oracle don't use my predefined index? [message #502527 is a reply to message #502525] Thu, 07 April 2011 01:09 Go to previous messageGo to next message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Did you read How to Identify Performance Problem and Bottleneck topic?

Regards
Michel
Re: Why Oracle don't use my predefined index? [message #502529 is a reply to message #502527] Thu, 07 April 2011 01:13 Go to previous messageGo to next message
Tlg13team
Messages: 100
Registered: June 2008
Location: MGL
Senior Member
Hi Michel,

There are so many useful topics and i have read something.

Which section I must read?
Re: Why Oracle don't use my predefined index? [message #502532 is a reply to message #502529] Thu, 07 April 2011 01:21 Go to previous messageGo to next message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
This is not any topic, this is THE sticky of this forum, that is the topic you should read before posting any question in this forum.

If you click on the link, you will find a section named "Why Oracle does not use my index?".

Regards
Michel

[Updated on: Thu, 07 April 2011 01:23]

Report message to a moderator

Re: Why Oracle don't use my predefined index? [message #502542 is a reply to message #502532] Thu, 07 April 2011 02:30 Go to previous messageGo to next message
Tlg13team
Messages: 100
Registered: June 2008
Location: MGL
Senior Member
I'm sorry a bit hurried up when create duplicate content post without search this forum..

I found answer url below:

https://communities.bmc.com/communities/docs/DOC-10031
Re: Why Oracle don't use my predefined index? [message #502544 is a reply to message #502542] Thu, 07 April 2011 02:43 Go to previous message
Roachcoach
Messages: 1576
Registered: May 2010
Location: UK
Senior Member
Interesting article, although I get different reults in 11gR2, so YMMV

Edit: And in version 9.2

SCOTT@ORA11GMK > create table t1 as
  2  select
  3  trunc((rownum-1)/15)  n1,
  4  trunc((rownum-1)/15)       n2,
  5  rpad('x', 215)        v1
  6  from all_objects
  7  where rownum <= 3000;

Table created.

Elapsed: 00:00:00.53
SCOTT@ORA11GMK > create table t2 as
  2  select
  3  mod(rownum,200) n1,
  4  mod(rownum,200) n2,
  5  rpad('x',215) v1
  6  from all_objects
  7  where rownum <= 3000;

Table created.

Elapsed: 00:00:00.60
SCOTT@ORA11GMK > create index t1_i1 on t1(N1);

Index created.

Elapsed: 00:00:00.06
SCOTT@ORA11GMK > create index t2_i1 on t2(n1);

Index created.

Elapsed: 00:00:00.14
SCOTT@ORA11GMK > analyze table t1 compute
  2  statistics;

Table analyzed.

Elapsed: 00:00:00.10
SCOTT@ORA11GMK > analyze table t2 compute
  2  statistics;

Table analyzed.

Elapsed: 00:00:00.07
SCOTT@ORA11GMK > explain plan for
  2  select * from t1 where n1 = 45;

Explained.

Elapsed: 00:00:00.06
SCOTT@ORA11GMK > select * from table(dbms_xplan.display());

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------
Plan hash value: 1429545322

-------------------------------------------------------------------------------------
| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |       |    15 |  3315 |     2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| T1    |    15 |  3315 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | T1_I1 |    15 |       |     1   (0)| 00:00:01 |
-------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("N1"=45)

14 rows selected.

Elapsed: 00:00:00.79
SCOTT@ORA11GMK > explain plan for
  2  select * from t2 where n1 = 45;

Explained.

Elapsed: 00:00:00.04
SCOTT@ORA11GMK > Select * from table(dbms_xplan.display());

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------
Plan hash value: 365331496

-------------------------------------------------------------------------------------
| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |       |    15 |  3315 |    16   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| T2    |    15 |  3315 |    16   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | T2_I1 |    15 |       |     1   (0)| 00:00:01 |
-------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("N1"=45)

14 rows selected.

Elapsed: 00:00:00.07

[Updated on: Thu, 07 April 2011 02:47]

Report message to a moderator

Previous Topic: Execution plan question
Next Topic: How to index 15 columns when you cannot predict what columns will be used in a where clause?
Goto Forum:
  


Current Time: Sun Nov 24 20:39:13 CST 2024