Analyse this; Learning from the optimizer

September 9th, 2010 | Posted in Blog, oracle optimizer, Uncategorized | 2 Comments



The following question appeared today on the Oracle Forum,

Oracle version is: 10.2.0.4
The hint /*+ index (t (STATUS) ) */ doesn’t work.
Table t has index with column status.

If I explicit set index name /*+ index (t IDX2) */ – works fine.
Why setting of column name does not work? Is there an additional condition for using it?

I have added this comment to highlight the post for interested readers.
According to the Oracle documentation, the syntax is correct:

References:

http://download.oracle.com/docs/cd/E11882_01/server.112/e10821/hintsref.htm#CHDCCFCC

So I have asked the Original Poster – OP to provide me the table definition and the explain plan of both queries. Below you can find his / her answer:

create table BIG_TBL
(
owner VARCHAR2(30) not null,
object_name VARCHAR2(30) not null,
subobject_name VARCHAR2(30),
object_id NUMBER not null,
data_object_id NUMBER,
object_type VARCHAR2(19),
created DATE not null,
last_ddl_time DATE not null,
timestamp VARCHAR2(19),
status VARCHAR2(7) not null,
temporary VARCHAR2(1),
generated VARCHAR2(1),
secondary VARCHAR2(1)
)

create index IDX_BIG_TBL_CREATED on BIG_TBL (CREATED);
create index IDX_BIG_TBL_CREATED2 on BIG_TBL (CREATED, OBJECT_ID, STATUS, TIMESTAMP, DATA_OBJECT_ID);

set column name

SQL> explain plan for
2 select /*+ index(t (status)) */
3 status
4 from big_tbl t
5 where status is not null
6 ;

Explained

SQL> @C:\oracle\product\10.2.0\plan.sql
Plan hash value: 859430865
—————————————————————————–
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
—————————————————————————–
| 0 | SELECT STATEMENT | | 3383K| 22M| 15765 (1)| 00:02:54 |
| 1 | TABLE ACCESS FULL| BIG_TBL | 3383K| 22M| 15765 (1)| 00:02:54 |

set index name

SQL> explain plan for
2 select /*+ index(t IDX_BIG_TBL_CREATED2) */
3 status
4 from big_tbl t
5 where status is not null
6 ;

Explained

SQL> @C:\oracle\product\10.2.0\plan.sql
Plan hash value: 2228401533
—————————————————————————————–
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
—————————————————————————————–
| 0 | SELECT STATEMENT | | 3383K| 22M| 190K (1)| 00:34:56 |
| 1 | INDEX FULL SCAN | IDX_BIG_TBL_CREATED2 | 3383K| 22M| 190K (1)| 00:34:56 |
—————————————————————————————–

8 rows selected

I have simulated this on my test database and here are the results:

A1
A2
A3
A4

My conclusion: When you want to include the column name in the index hint, be sure that this column has a full index dedicated only and just for it. Otherwise, specify all the column names that have been part of the index itself. I am still learning from the optimizer ;)

Thanks,
Wissem

Scridb filter


2 Comments to “Analyse this; Learning from the optimizer”

  1. Hello, first of all, I want to say it’s a great weblog you have here. However, I haven’t understood the way to include your site feed in my rss reader, where is the link to your feed? Thank you

    • orawiss says:

      Hello Necole,
      Thank you for your comment. You can subscribe by just clicking in the Email Subscription that appears in every blog page. After that and for any new post you will get automatically an email.
      Cheers,
      Wissem


Leave a Comment





Subscribe


Polls

which oracle topic interests you most?

View Results

Loading ... Loading ...


Oracle Class Tweets


Recent Posts


Recent Comments

  • Jaspreet: Brilliant explanation.
  • Yousuf: Very Nice… Just wanted to check you have done all patching at Node 1 only.. is there any thing need to...
  • Yousuf: Very Nice.. Thanks for sharing.. Once question.. You have executed all commands on Node 1 only.. Is there any...
  • Emir: Thanks… Great article
  • borse firmate: Thank you for another informative blog. The place else may just I am getting that kind of information...
  • leandro: why this parameter is systemwide? could you read from a asm instance from one failure group and from the...
  • Mohammad: paul, we create pfile from target database to source database and later we change database name, and...
  • Muhammad Ikram: Thanks Brother for sharing pearls of knowledge. May ALLAH reward you for this both here and...
  • rgrover: Thanks for the POST. I recently encounter similar issue. Your POST helped.
  • gopalredy: really its very use full to dbas
  • Vivian: This is awesome! Thank you so much!
  • henry zhong: CDB=DB, and PDB=SCHEMA but in a sub dictionary?
  • Dehbashee: Salam Brother, Thanx for sharing, however, i would be interested in chaging the password for the grid user...
  • wissem: No we don’t need that :) Just the scripts I posted above
  • Md. Tanweer: Thanks for posting the material. I really appreciate if you can send me, if you have tutorial for 11g...
  • christiaan: Thanks!! This has been bugging the hell out of me for so long.
  • Rajasekhar: Thank you
  • Samarjit Panigrahy: Very Nice and Simple Demo… Cool :)
  • cq: Any reason not to use auto patch for both CRS and RAC homes with one command? Or use opatch auto for RAC home as...
  • Hitesh: Hi, Can we use this RACcheck tool on oracle SE version ? Thanks