现在用table1和table2create or replace view table3 as select t1.fcode, t1.fname from table1 union all select t2.fcode, t2.fname from table2table1和table2中的FCODE都是主键, 现在我用table3关联检索数据的时候, 发现table3这个视图是全表扫描的 这个导致速度很慢,哪位有解决办法呀?
我的sql语句是这么写的: select t3.* from table3 t3, TmpPickup m where t3.fcode = m.fstore;TmpPickup是个临时表, 这样的语句执行一下的话,发现对table3表是全表扫描的。而我用 select t1.* from table1 t1, TmpPickup m where t1.fcode = m.fstore; 执行的时候,对table1是用到主键的。
而我又不得不用table3,所以就想请教各位,这个时候怎么让速度提高起来呀?视图上面又不能建索引
语法是: create materialized view yourview ...create index on yourview(col1,col2,...);
select t3.*
from table3 t3, TmpPickup m
where t3.fcode = m.fstore;TmpPickup是个临时表,
这样的语句执行一下的话,发现对table3表是全表扫描的。而我用
select t1.*
from table1 t1, TmpPickup m
where t1.fcode = m.fstore;
执行的时候,对table1是用到主键的。
create materialized view yourview
...create index on yourview(col1,col2,...);
from table3 t3, TmpPickup m
where t3.fcode = mycode
的话,9i以上数据库会优化sql并使用索引,如果临时表里数据不多,使用动态构造sql的方式实现吧
select /*+ index(mytable myindex) */ from mytable;就这样