DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: performance of Indexes in Composite key

Threaded View

  1. #3
    Join Date
    Sep 2001
    Location
    Düsseldorf, Germany.
    Posts
    588
    1. It will/will not use a composite index for two first queries though the columns mentioned in the WHERE clause aren't as specified in the index defination (sequence of column specification). BUT It will definately improve the speed of retrival of data if you specify the sequence of the columns in the WHERE condition as you specified in the index defination. As it is always recommended

    Look at the follwing example.

    Code:
    SQL> CREATE TABLE test AS SELECT object_id, object_name, object_type FROM all_objects;
    
    Table created.
    
    SQL> CREATE INDEX ix_test ON test (object_id, object_type);
    
    Index created.
    
    SQL> SELECT object_name FROM test WHERE object_id = 1199  AND object_type = 'VIEW';
    
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TEST'
       2    1     INDEX (RANGE SCAN) OF 'IX_TEST' (NON-UNIQUE)
    
    SQL> SELECT object_name FROM test
      2    WHERE object_type = 'VIEW' AND  object_id = 1199;
    
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TEST'
       2    1     INDEX (RANGE SCAN) OF 'IX_TEST' (NON-UNIQUE)
    
    
    -- only second column has been specified in the WHERE clause
    so it doesn't use the index.
    
    SQL> SELECT object_name FROM test
      2  WHERE object_type = 'VIEW' ;
    
    1155 rows selected.
    
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   TABLE ACCESS (FULL) OF 'TEST'
    
    
    SQL> SELECT object_name FROM test WHERE object_id = 1199;
    
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TEST'
       2    1     INDEX (RANGE SCAN) OF 'IX_TEST' (NON-UNIQUE)
    
    
    -- Here you force optimizer to user index by suppling hint
    
    SQL> SELECT /*+ INDEX (test, ix_test) */ object_name FROM test  WHERE object_type = 'VIEW' ;
    
    1155 rows selected.
    
    
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=34 Card=10 Bytes=280
              )
    
       1    0   TABLE ACCESS (BY INDEX ROWID) OF 'TEST' (Cost=34 Card=10 B
              ytes=280)
    
       2    1     INDEX (FULL SCAN) OF 'IX_TEST' (NON-UNIQUE) (Cost=26 Car
              d=10)
    Last edited by Sameer; 01-23-2003 at 10:01 AM.

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