9

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

4

3 回答 3

14

使用 NO_INDEX 提示

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

例如

SELECT /*+ NO_INDEX(t1 id1) */ 
  FROM t1,
       t2  
 WHERE t1.id = t2.id;
于 2013-06-17T06:45:56.390 回答
3

有一个一般原则,对于要为其指定执行计划的每个查询,每个表都需要两个或三个提示。

在这种情况下,您可能正在寻找由两次全表扫描产生的散列连接,这相当简单,因此提示块类似于:

select /*+ full(t1) full(t2) use_hash(t1 t2) */
...
于 2013-06-17T10:10:22.753 回答
3

您可以通过对其应用函数来防止在没有提示的情况下在列上使用索引。您将需要使用“no-op”功能,以便不会更改列值。对于数字,这可能是添加零,对于附加空字符串的字符串:

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

于 2013-06-17T14:56:21.153 回答