pl/sql视图查询优化视图:vw_detail_new执行以下:
select * from vw_detail_new WHERE ACCUSE_TYPE ='出租车'
   AND 是否回访  ='否'    
   AND if_shenhe = '1'
   AND OBJECT_TYPE = '投诉'  查询时间为6.30s (3000条记录)--------------------------------------------------------
但添加时间条件后 :
select * from vw_detail_new WHERE ACCUSE_TYPE ='出租车'
   AND 是否回访  ='否'    
   AND if_shenhe = '1'
   AND OBJECT_TYPE = '投诉' 
AND 办结时间 >=
       to_date('2010-12-02' || ' 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
   AND 办结时间 <=
       to_date('2010-12-03' || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')查询时间为 110.56s  (300条记录)为何时间筛选这么耗时?如何优化该视图?-------------------------------视图:vw_detail_new-----------------------------------------CREATE OR REPLACE VIEW vw_detail_new AS
select
t.C_ID,Handle_no,Accuser_name,Accuser_route,if_shenhe,(case when (select count(*) from t_accuse_history h where h.c_master=t.c_id and h.c_status='2ADBAFFC43954BF4993AFFF511589817')>0  then (select x.c_mingcheng from t_qiyejbxx x where x.c_id=TAXI_DEPT_ID) else '' end) as 协查企业,(SELECT c_mingcheng FROM t_daima WHERE c_id=ACCUSE_TYPE) AS ACCUSE_TYPE,
(select c_mingcheng from t_daima where c_id=STATUS) as status,(case when if_fenfa is null or if_fenfa='0' then 0 else 1 end) as 分发条件,
(case when (select count(*) from t_accuse_revisit r where r.accuseid=t.c_id)>0  then '是' else '否' end) as 是否回访,(select  HANDLE_RESULT_QY from T_ACCUSE_QYJY where ACCUSEID=t.C_ID and rownum<2) as HANDLE_RESULT_QY,(select max(h.c_date) from t_accuse_history h where h.c_master=t.C_ID and h.c_status='B540AFA5EBAA4DC9BFA4BE59478AFD94') as 办结时间,F_GetTimeOutQY(t.c_id) as 待协查操作时限,
F_GetTimeOutDept(t.c_id) as 转部门操作时限,from
t_accuse t where if_shenhe = '1' 

解决方案 »

  1.   

    做报表吗?如果不是的牺牲点磁盘空间来换性能吧。
    我仔细看了下,都是通过id获取名字的情况,关联太多了
    还不如在t_accuse 加几个字段存储这样名字,虽然数据冗余了,但是换回不少性能。。
      

  2.   

    加了时间条件后查询更慢:
    AND 办结时间 >=
      to_date('2010-12-02' || ' 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
      AND 办结时间 <=
      to_date('2010-12-03' || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
    加别的条件筛选时,查询时间可以接受
      

  3.   

    1:AND 办结时间 >=
      to_date('2010-12-02' || ' 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
      AND 办结时间 <=
      to_date('2010-12-03' || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')改成BETWEEN试试2:F_GetTimeOutDept(t.c_id) as 转部门操作时限,from
     多了个,号3:WHERE 办结时间 >=
      to_date('2010-12-02' || ' 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
      AND 办结时间 <=
      to_date('2010-12-03' || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
     AND ACCUSE_TYPE ='出租车'
      AND 是否回访 ='否'   
      AND if_shenhe = '1'
      AND OBJECT_TYPE = '投诉' 把时间放到WHERE的后面,因为如果走RBO的话,WHERE 是先执行最后的筛选,然后依次往前的