日期:2014-05-17  浏览次数:21125 次

如何让index hint透过视图使用
drop table t1;
drop table t2;
drop table t3;
drop view v_3;

create table t1 
(f1 integer,
f2 varchar2(10));

create table t2 
(f1 integer,
f2 varchar2(10));
create index ind_t2 on t2(f2);

create table t3 
(f1 integer,
f2 varchar2(10));
create index ind_t3 on t3(f2);


create or replace view v_3
as
select f1,f2 from t2
union all
select f1,f2 from t3


-- 如何让下面的查询用到t2,t3上的索引

select /*+ordered use_nl(t1,v_3)*/t1.*
from t1,v_3
where t1.f1 = 1
  and t1.f2 = v_3.f2



------解决方案--------------------
從執行計劃看到已經使用t2,t3的索引了
------解决方案--------------------
ORACLE版本?

贴出你的执行计划。
------解决方案--------------------
view上面的查询,Oracle会自动选择走表上面的索引的!如果你要hint来做的。不妨用MView吧!