How to force oracle to not to use an index
Asked Answered
L

3

10

I have a requirement in which i have to force the sql not to use a particular index which exists on a table.

for example,

create table t1(id varhcar2(10),data1 varchar2(3000));
create table t2(id varhcar2(10),data2 varchar2(3000));

create index id1 on t1(id);

select * from t1,t2 where t1.id=t2.id;

I cannot drop the index id1 and neither drop it as i dont have rights on it. therefore i want to add some kind of hint to avoid using it..

Is there any such hint, or is there any workaround for this.

Thanks in advance

Least answered 17/6, 2013 at 6:34 Comment(0)
S
15

Try using NO_INDEX hint

For instance

SELECT /*+ NO_INDEX(t1 id1) */ 
  FROM t1,
       t2  
 WHERE t1.id = t2.id;
Stegman answered 17/6, 2013 at 6:45 Comment(0)
A
4

There's a general principle that for every query for which you want to specify the execution plan, you need something like two or three hints per table.

In this case, you're probably looking for a hash join resulting from two full table scans, which is fairly simple so the hint block would be something like:

select /*+ full(t1) full(t2) use_hash(t1 t2) */
...
Andesite answered 17/6, 2013 at 10:10 Comment(0)
C
3

You can prevent the use of an index on a column without hints by applying a function to it. You'll want to use a "no-op" function so the column values aren't changed. For numbers this could be adding zero, for strings appending the empty string:

select * from t1,t2 where t1.id || '' =t2.id;

Cobalt answered 17/6, 2013 at 14:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.