Nov 11 2008

Invisible Indexes and Hints

Tag: 11gR1, Bug, Indexes, Query OptimizerChristian Antognini @ 6:02 pm

In this post I would like to remove some misinformation about the utilization of hints with invisible indexes.

Let’s start by providing you what two sources say about that topic:

Both sources point out that a hint can be used to compel the query optimizer to use an invisible index. Both also provide an example (not shown here). But, what is more important, both are wrong! In other words, a hint cannot be used to compel the query optimizer to use an invisible index.

What’s going on?!?

The problem is that this specific information used to be correct for the beta release of Oracle Database 11g. But that behavior was a bug, not a feature! Therefore, once the bug was fixed, this piece of information was no longer valid.

This is what happens when authors use beta releases for doing their tests…

5 Responses to “Invisible Indexes and Hints”

  1. Comment: Radoslav Golian

    Good remark, thank you. I didn’t know that this was a bug.

  2. Comment: Arup Nanda

    You are right, Chris. And I apologize for not responding to it earlier.
    I was referred to this literally hours ago. Sometimes things change albeit
    in small amounts between beta and production. Those articles were reviewed
    by Oracle PM and they were supposed to have caught that. Well…. Anyway,
    that’s not an excuse; but just a background.

    In 11gR2, the series will be written with production code alone.

  3. Comment: Christian Antognini

    Hi Arup

    I sympathize with that… I know that editors want to have books (in your case, articles) as soon as the production release is available and, therefore, authors are pushed to work with beta releases. Hence, there are good chances that something like that happens.

    I originally wrote this post because I heard that specific “myth” too many times! I though it was good to stop it. Or, at least, to try…

    It’s good to know that for 11gR2 it will be different.

    Cheers,
    Chris

  4. Comment: Mark Lancaster

    Hi Chris

    An update on invisible indexes and hints.
    Oracle introduced the USE_INVISIBLE_INDEXES hint in 11.1.0.6, so provided your patched up it works correctly.

    e.g. select /*+ USE_INVISIBLE_INDEXES */ * from your_table;

    In fact they added quite a few new hints, see the V$SQL_HINT view for details.

    Regards

    Mark

  5. Comment: Christian Antognini

    Hi Mark

    Thank you very much for your comment. It points out an important thing…

    To make things clear, in my post I was speaking about hints like INDEX and not the new hint USE_INVISIBLE_INDEXES. Let me give an example to make the point cristal clear to everyone ;-)

    SQL> EXPLAIN PLAN FOR SELECT * FROM t1 WHERE n = 1;
    
    SQL> SELECT * FROM table(dbms_xplan.display(format=>'basic'));
    
    PLAN_TABLE_OUTPUT
    ----------------------------------
    Plan hash value: 3617692013
    
    ----------------------------------
    | Id  | Operation         | Name |
    ----------------------------------
    |   0 | SELECT STATEMENT  |      |
    |   1 |  TABLE ACCESS FULL| T1   |
    ----------------------------------
    
    SQL> EXPLAIN PLAN FOR SELECT /*+ index(t1) */ * FROM t1 WHERE n = 1;
    
    SQL> SELECT * FROM table(dbms_xplan.display(format=>'basic'));
    
    PLAN_TABLE_OUTPUT
    ----------------------------------
    Plan hash value: 3617692013
    
    ----------------------------------
    | Id  | Operation         | Name |
    ----------------------------------
    |   0 | SELECT STATEMENT  |      |
    |   1 |  TABLE ACCESS FULL| T1   |
    ----------------------------------
    
    SQL> EXPLAIN PLAN FOR SELECT /*+ use_invisible_indexes */ * FROM t1 WHERE n = 1;
    
    SQL> SELECT * FROM table(dbms_xplan.display(format=>'basic'));
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------
    Plan hash value: 100931685
    
    --------------------------------------------
    | Id  | Operation                   | Name |
    --------------------------------------------
    |   0 | SELECT STATEMENT            |      |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T1   |
    |   2 |   INDEX RANGE SCAN          | I_N  |
    --------------------------------------------

    Cheers,
    Chris

Leave a Reply

All comments are filtered by Akismet and then moderated by me. So, it should be no surprise that spam and anything wholly inappropriate has no chance of making it onto the site. To send questions or comments not related to this blog post please use the contact form.

Your name (required)

Your email (will not be published) (required)

Your website

Your message (please wrap code examples in <pre> tags)