Pergunta

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

Foi útil?

Solução

use NO_INDEX hint

http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements006.htm#BABHJBIB

for instance

SELECT /*+ NO_INDEX(t1 id1) */ 
  FROM t1,
       t2  
 WHERE t1.id = t2.id;

Outras dicas

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) */
...

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;

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top