SELECT distinct col from v_view1
where trunc(datetime1) >= to_date('20010101','yyyymmdd') 
  and trunc(datetime1) <= to_date('20030508','yyyymmdd')
  and string1 like '13302%'
  and flag='1';
由于视图 v_view1中有一个表很大(超过3千万条记录),所以仅这一个查询语句就需要100多秒,请大家帮忙优化一下!!!
 

解决方案 »

  1.   

    SELECT distinct col from v_view1
    where datetime1 >= to_date('20010101','yyyymmdd') 
      and datetime1 < to_date('20030509','yyyymmdd')
      and string1 like '13302%'
      and flag='1';还有就是datetime1、string1、flag哪些在那个大表中,视图中的各个表的连接条件是否合理,是否可以用上索引,是否建立了合适的索引......
      

  2.   

    SELECT distinct col from v_view1
    where datetime1 >= to_date('20010101 23:59:59','yyyymmdd hh24:mi:ss') 
      and datetime1 <= to_date('20030508 23:59:59','yyyymmdd hh24:mi:ss')
      and string1 like '13302%'
      and flag='1';
    datetime string1 flag创建索引