DBAsupport.com Forums - Powered by vBulletin
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Index usage questions

  1. #1
    Join Date
    Sep 2000
    Location
    Chicago, IL
    Posts
    316

    Index usage questions

    Table in question: Orders
    Index A on Table Orders (order_number, issue_symbol, firm_symbol)

    Query in question:
    select * from orders
    where firm_symbol = 'ABCD'
    and issue_symbol = 'IBM'
    and order_side = 'B'
    and msg_key_time > '100423';

    After doing a trace on this query, it does a full table scan. Index hint also does not work. Table/indexes are analyzed.
    Why does it not use index A, should it ? since 2 of the 3 columns are in the index.

    Is there anything else I can try, other than creating another index ?

  2. #2
    Join Date
    Nov 2000
    Location
    Baltimore, MD USA
    Posts
    1,339
    In 8i, it will only use an index if a left-leading sub-set of the columns are used in the predicates. Since you are not using order_number, the index will not be used.

    9i has new capabilities in this area.

    - Chris
    Christopher R. Long
    ChrisRLong@HotMail.Com
    But that's just my opinion. I could be wrong

  3. #3
    Join Date
    Sep 2000
    Location
    Chicago, IL
    Posts
    316
    Thanks Chris, can u give some more details on 9i capabilities that u refered to, that is what we are using.

    Should this query not use index skip scan ?
    Last edited by khussain; 05-16-2003 at 12:57 PM.

  4. #4
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    index skip-scan requires a low number of distinct values in the leading columns of the index. I'm guessing from the table and column names that order_number would not meet that restriction.
    David Aldridge,
    "The Oracle Sponge"

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

    Oracle ACE

  5. #5
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    Try this:

    select * from orders
    where order_number = order_number
    and firm_symbol = 'ABCD'
    and issue_symbol = 'IBM'
    and order_side = 'B'
    and msg_key_time > '100423';

    I am not sure the above sql will use index.
    Give a shot.

  6. #6
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    Originally posted by tamilselvan
    Try this:

    select * from orders
    where order_number = order_number
    and firm_symbol = 'ABCD'
    and issue_symbol = 'IBM'
    and order_side = 'B'
    and msg_key_time > '100423';

    I am not sure the above sql will use index.
    Give a shot.
    I hope it doesn't, and I don't think it will.
    David Aldridge,
    "The Oracle Sponge"

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

    Oracle ACE

  7. #7
    Join Date
    May 2003
    Location
    hyderabad, India
    Posts
    10
    HI

    Use this query, it uses the index and i have checked it in the plan_table.

    --------------------------------------------------------
    select /*+ INDEX(ORDERS A) */ * from orders
    where
    order_number=order_number
    and issue_symbol = 'IBM'
    and firm_symbol = 'ABCD'
    and order_side = 'B'
    and msg_key_time > '100423';

    --------------------------------------------------------

    Actually the where clause column order should be in the same order as specified during the creation of the index. i have used the same concept and the hint(index) to force the usage of the index.

    I am attaching the execution plan and the statistics for ur reference.

    Regards

    Partha

  8. #8
    Join Date
    Jun 2000
    Location
    Madrid, Spain
    Posts
    7,447
    if you use a hint of course it uses index but of course if will go much sloswer

    also, since when the order of predicate has to be the same as index....? any reference for that?

  9. #9
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    Originally posted by pando
    if you use a hint of course it uses index but of course if will go much sloswer

    also, since when the order of predicate has to be the same as index....? any reference for that?
    Excellent points. Partha is fired.
    David Aldridge,
    "The Oracle Sponge"

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

    Oracle ACE

  10. #10
    Join Date
    Dec 2002
    Location
    Bangalore ( India )
    Posts
    2,434
    Originally posted by chrisrlong
    In 8i, it will only use an index if a left-leading sub-set of the columns are used in the predicates. Since you are not using order_number, the index will not be used.

    9i has new capabilities in this area.

    - Chris
    Chris :

    Not sure i follow you...take a look.

    Code:
    SQL*Plus: Release 8.1.7.0.0 - Production on Sun May 18 07:04:28 2003
    
    (c) Copyright 2000 Oracle Corporation.  All rights reserved.
    
    Enter password: ********
    
    Connected to:
    Oracle8i Enterprise Edition Release 8.1.7.4.1 - Production
    JServer Release 8.1.7.4.1 - Production
    
    SCS_DBA@U144> set lines 10000
    SCS_DBA@U144> select material_no from ship_fcst where FCST_PERIOD_DT = '01-may-03' and rownum < 2;
    
    MATERIAL_NO
    ------------------
    110936-B21
    
    
    Execution Plan
    ----------------------------------------------------------
              0                    SELECT STATEMENT Optimizer=CHOOSE (Cost=2948 Card=100967 Bytes=1716439)
              1                  0   COUNT (STOPKEY)
              2                  1     INDEX (FAST FULL SCAN) OF 'PK_SHIP_FCST' (UNIQUE) (Cost=2948 Card=100967 Bytes=1716439)
    
    
    -- Note Index (PK_SHIP_FCST) Being Used...
    
    now see the index postion of FCST_PERIOD_DT
    
    SCS_DBA@U144> ed
    Wrote file afiedt.buf
    
      1  select column_position, index_name, table_name, column_name from dba_ind_columns where
      2* index_name='PK_SHIP_FCST' order by  column_position
    SCS_DBA@U144> /
    
    COLUMN_POSITION INDEX_NAME                     TABLE_NAME                     COLUMN_NAME
    --------------- ------------------------------ ------------------------------ -----------------------------------
                  1 PK_SHIP_FCST                   SHIP_FCST                      PLANT_CD
                  2 PK_SHIP_FCST                   SHIP_FCST                      MATERIAL_NO
                  3 PK_SHIP_FCST                   SHIP_FCST                      SALES_ORGANIZATION_CD
                  4 PK_SHIP_FCST                   SHIP_FCST                      FCST_BASE_PERIOD_DT   
                  5 PK_SHIP_FCST                   SHIP_FCST                      FCST_PERIOD_DT
                  6 PK_SHIP_FCST                   SHIP_FCST                      VERSION_STAT_NM
    
    6 rows selected.
    funky...

    "I Dont Want To Follow A Path, I would Rather Go Where There Is No Path And Leave A Trail."

    "Ego is the worst thing many have, try to overcome it & you will be the best, if not good, person on this earth"

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