Is there any way to an index that can be used to include the "OR condition "?

Hello I have some questions.
The test was conducted in the following procedure .
create table test
c1 varchar2(10),
c2 varchar2(10),
primary key(c1)
create index test_idx1 on test(c2);
Command> explain select * from test where c1 = 'AAAAAAAAAA' or c2 = 'AAAAAAAAAA';
Query Optimizer Plan:
  STEP:                1
  LEVEL:               1
  OPERATION:           RowLkRangeScan
  TBLNAME:             TEST
  IXNAME:              TEST
  INDEXED CONDITION:   <NULL>
  NOT INDEXED:         TEST.C2 = 'AAAAAAAAAA' OR TEST.C1 = 'AAAAAAAAAA'
Command>
Command> explain select * from test where c1 = 'AAAAAAAAAA' and c2 = 'AAAAAAAAAA'
Query Optimizer Plan:
  STEP:                1
  LEVEL:               1
  OPERATION:           RowLkRangeScan
  TBLNAME:             TEST
  IXNAME:              TEST
  INDEXED CONDITION:   TEST.C1 = 'AAAAAAAAAA'
  NOT INDEXED:         TEST.C2 = 'AAAAAAAAAA'
Command>
By including the "OR condition " in this test does not use the index.
Is there any way to an index that can be used to include the "OR condition "?
Thanks.
GooGyum.

A database cannot in general use indexes in this way for an 'or' involving two different columns. However, for this specific example one can easily rewrite the query using 'UNION' to use the relevant indexes while still giving the same (correct) result:
Command> explain select * from test t1 where t1.c1 = 'AAAAAAAAAA' union select * from test t2 where t2.c2 = 'AAAAAAAAAA';
Query Optimizer Plan:
  STEP:                1
  LEVEL:               1
  OPERATION:           RowLkRangeScan
  TBLNAME:             TEST
  IXNAME:              TEST
  INDEXED CONDITION:   T1.C1 = 'AAAAAAAAAA'
  NOT INDEXED:         <NULL>
  STEP:                2
  LEVEL:               2
  OPERATION:           RowLkRangeScan
  TBLNAME:             TEST
  IXNAME:              TEST_IDX2
  INDEXED CONDITION:   T2.C2 = 'AAAAAAAAAA'
  NOT INDEXED:         <NULL>
  STEP:                3
  LEVEL:               1
  OPERATION:           OrderBy
  TBLNAME:             <NULL>
  IXNAME:              <NULL>
  INDEXED CONDITION:   <NULL>
  NOT INDEXED:         <NULL>
  STEP:                4
  LEVEL:               2
  OPERATION:           UnionMergeSort
  TBLNAME:             <NULL>
  IXNAME:              <NULL>
  INDEXED CONDITION:   <NULL>
  NOT INDEXED:         <NULL>
Maybe you can apply a similar trick? If you know there is no possibility of duplicate rows then you can further optimise this (in terms of performance) by using UNION ALL.
Chris

Similar Messages

Maybe you are looking for

  • Install error 11gR2 on Windows 2008 Server R2

    Hello, I have a question about an installation error I received on Windows 2008 Server R2 while trying to install the 11g R2 on an test machine. I had downloaded both cd's and extracted them and copied the first cd into an new directory and then trie

  • How to call system command to launch Windows Explorer

    Hello, I'd like to open the windows explorer from java.... anyone know how this is done? thanks

  • Specular Highlight colour problem - Leica M8 RAW files

    I have sent feedback to Apple regarding this problem. Use of the moire slider does not eliminate the coloured dots on bright specular highlights, for example sun reflecting off water droplets. By comparison, Capture One software produces bright white

  • Setting charset in HTML generated by Reports 6i

    How can I define charset in html generated by Reports 6i. I need windows-1250 charset. Adding the following line in Before Report Value does not help. <meta http-equiv="content-type" content="text/html; charset=windows-1250"> Note: If I open that gen

  • Laptop to desktop transferring

    Hiya, I take a lot of photos while on the road and like to upload them to my MacBook and then back up the whole library onto an external drive that I carry as well. And then when I'm home I transfer the images from my MacBook to my iMac, no problem.