表的数据有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');查询该视图时非常慢,请问有什么办法可以提供性能吗?
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');查询该视图时非常慢,请问有什么办法可以提供性能吗?
--想法就是使用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'))
在ztdm,czrq上面增加索引。
select distinct a.mlh,a.ztdm,a.czrylx from check_da a where a.ztdm='05' and a.czrq >= sysdate;不就OK了。如果还想提高那就去建索引了。