index and data conversion
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: index and data conversion

  1. #1
    Join Date
    Jun 2000
    Posts
    295

    index and data conversion

    Hi,

    Table test(col1 varchar2(32) not null,
    col2 number not null,
    other_columns,,,)
    index i_test on test(col1, col2)
    Query select ... from test
    where col1 = 'this is test'
    and col2 = '12345';

    I do not remember exactly whether I saw an article from
    AskTom.com, saying this data conversion (col2) may cause
    i_test index not being used.
    When I used autotrace trace only, I find the index
    is used.

    Even changing index on test(col2), the index
    is still used.

    Can someone ********?

    Thank you!
    Last edited by sysdba; 02-20-2003 at 02:23 PM.

  2. #2
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    the second column can be used through an "index skip-scan" access path in recent versions of Oracle -- also through a fast full index scan i suppose.
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

  3. #3
    Join Date
    Jun 2000
    Posts
    295
    Thank you, but I am using 8.1.7.

  4. #4
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    i expect it might depend what was in the select clause -- the fast full scan is available in 8.1.7, and effectively treats the index as a skinny table.
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

  5. #5
    Join Date
    Jun 2000
    Posts
    295
    I found similiar question:
    http://asktom.oracle.com/pls/ask/f?p...g4636346663651

    Tom said:
    === BEGIN OF WHAT TOM SAID ========
    If you have my book -- I answer your #3 question in "why isn't my index getting
    used" in the chapter on indexes. column XXX is a varchar2 column. You are
    comparing a string to a number. So

    select * from t where xxx = 123

    is REALLY

    select * from t where to_number(xxx) = 123;

    you are applying a function to the column XXX implicitly. That invalidates the
    index usage. When you code:

    select * from t where xxx = '123'

    you are comparing a string to a string and lo and behold -- no such conversion
    takes place.


    ALWAYS COMPARE STRINGS TO STRINGS, DATES TO DATES, NUMBERS TO NUMBERS. do not
    rely on implicit conversion -- ever!
    === END OF WHAT TOM SAID ========


    How about my where clause:
    A_NUMBER_COL = 'A_STRING_WHICH_CONTAIN_ONLY_DIGITS'
    ???

    Is the above query is:
    select ... from test where TO_CHAR(A_NUMBER_COL )='12345';
    or
    select ... from test where A_NUMBER_COL=TO_NUMBER('12345');

    According my test of whether an index is used, it seems
    to me that Oracle converts to:
    select ... from test where A_NUMBER_COL=TO_NUMBER('12345');

    Thanks

  6. #6
    Join Date
    Jun 2000
    Posts
    295
    I tested Tom's case (varchar2 col and where condition
    is a_varchar2_col = 123) and Tom is always correct as usual.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width