表的数据有200万左右,视图的语句为:create or replace view check_dab as
select distinct a.mlh,a.ztdm,a.czrylx from check_da a where a.ztdm='05' and a.czrq >= to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd');查询该视图时非常慢,请问有什么办法可以提供性能吗?

解决方案 »

  1.   

    select distinct a.mlh,a.ztdm,a.czrylx from check_da a where a.ztdm='05' and a.czrq >= to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd');看看执行计划
      

  2.   


     --想法就是使用exists代替distinct,这样会降低一定的时间开销
     --参考:
    alter session set nls_date_format='yyyy-mm-dd';
    create or replace view check_dab as
    select a.mlh,a.ztdm,a.czrylx 
    from check_da a 
    where exists(
          select 1
          from check_da b
          where a.col=b.col--这里是表的主键列
            and b.ztdm='05'
            and b.czrq >= to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd'))
      

  3.   

    create or replace view check_dab as select distinct a.mlh,a.ztdm,a.czrylx from check_da a where a.ztdm='05' and a.czrq >= trunc(sysdate);
    在ztdm,czrq上面增加索引。
      

  4.   

    请问里面的select 1   这个1是什么意思?
      

  5.   

    干嘛要转字符又转日期。浪费时间,直接
    select distinct a.mlh,a.ztdm,a.czrylx from check_da a where a.ztdm='05' and a.czrq >= sysdate;不就OK了。如果还想提高那就去建索引了。