现在用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这个视图是全表扫描的
这个导致速度很慢,哪位有解决办法呀?

解决方案 »

  1.   

    我的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是用到主键的。
      

  2.   

    而我又不得不用table3,所以就想请教各位,这个时候怎么让速度提高起来呀?视图上面又不能建索引
      

  3.   

    语法是:
    create materialized view yourview
    ...create index on yourview(col1,col2,...);
      

  4.   

    对普通的视图的理解存在偏差,其实普通的视图就是已经编译好的SQL语句而已,同时为了方便,没有特殊性.对于索引的使用,都是基于基表的,组合起来的语句能够在记表上利用到索引就可以利用,否则就是不行.
      

  5.   

    如果是select t3.*
    from table3 t3, TmpPickup m
    where t3.fcode = mycode
    的话,9i以上数据库会优化sql并使用索引,如果临时表里数据不多,使用动态构造sql的方式实现吧
      

  6.   

    create view myview as
    select /*+ index(mytable myindex) */ from mytable;就这样