参数查询,部分参数过滤查询结果非常慢

select dense_rank() over(order by b.prod_int_qty desc , b.prod_int_val desc , a.prod_cls_num ) as prod_rand ,
a.owner_id , sys_unit.unit_name , a.pmc_id , pmc.pmc_name , a.prod_cls_num , prod_cls_user.prod_name , prod_cls_user.description , prod_cls_user.full_name , prod_cls_user.edition ,
prod_cls_user.main_type , prod_cls_user.gender , prod_cls_user.year_val , prod_cls_user.std_unit_price , prod_cls_user.input_code ,
a.color_name , a.color_int_qty , a.color_int_val , b.prod_int_qty , b.prod_int_val
from
(select sys_unit.owner_id ,  ori.pmc_id , prod_cls.prod_cls_num , prod_color.color_name ,  sum(ori_dtl.int_qty) as color_int_qty, sum(ori_dtl.int_val) as color_int_val
from ori, ori_dtl , sys_unit , product , prod_cls , prod_color
where ori.unit_id = ori_dtl.unit_id and ori.ori_num = ori_dtl.ori_num and ori.unit_id = sys_unit.unit_id
and ori_dtl.prod_id = product.prod_id and product.prod_cls_id = prod_cls.prod_cls_id and prod_color.color_id = product.color_id and ori.cancelled = 'F'
group by sys_unit.owner_id ,  ori.pmc_id , prod_cls.prod_cls_num , prod_color.color_name)
as a
inner join
(select sys_unit.owner_id ,  ori.pmc_id , prod_cls.prod_cls_num , sum(ori_dtl.int_qty) as prod_int_qty, sum(ori_dtl.int_val) as prod_int_val
from ori, ori_dtl , sys_unit , product , prod_cls
where ori.unit_id = ori_dtl.unit_id and ori.ori_num = ori_dtl.ori_num and ori.unit_id = sys_unit.unit_id
and ori_dtl.prod_id = product.prod_id and product.prod_cls_id = prod_cls.prod_cls_id and ori.cancelled = 'F'
group by sys_unit.owner_id ,  ori.pmc_id , prod_cls.prod_cls_num )
as b on a.owner_id = b.owner_id and a.pmc_id = b.pmc_id and a.prod_cls_num = b.prod_cls_num
left join pmc on pmc.pmc_id = a.pmc_id and pmc.unit_id = a.owner_id
left join prod_cls_user on prod_cls_user.prod_cls_num = a.prod_cls_num
/*prod_cls_user为视图,因为需要调用太多表而且使用频率很高,所有就做了个视图*/
left join sys_unit on a.owner_id = sys_unit.unit_id
where  1=1
${if(len(pmc_name) == 0,   "", "and pmc_name in ('" + pmc_name + "')")}
${if(len(unit_name) == 0,   "", "and unit_name in ('" + unit_name + "')")}
${if(len(main_type) == 0,   "", "and main_type in ('" + main_type + "')")}
${if(len(full_name) == 0,   "", "and full_name in ('" + full_name + "')")}
/*红色部分两个参数全部是通过视图来查询出来的,目前这两个参数查询的时候比不过滤还慢*/
order by b.prod_int_qty desc , b.prod_int_val desc , a.prod_cls_num

是不是因为视图的原因才出现main_type和full_name这两个参数一旦进行过滤就慢了?

FineReportbluejq 发布于 2015-9-10 12:54
悬赏:0 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共6回答
最佳回答
0
HaiBao发布于2015-9-10 12:54(编辑于 2023-9-6 09:34)
555
  • bluejq bluejq(提问者)

    所有字段均没加索引,目前就视图中的字段过滤慢
    回复
    2015-09-10 17:00 
最佳回答
0
HaiBao发布于2015-9-10 16:17(编辑于 2023-9-6 09:34)
555
  • bluejq bluejq(提问者)

    主要还是想确认下是不是视图的原因,因为如果我不用参数去过滤的话速度还是能接受的,过滤的反而慢了
    回复
    2015-09-10 16:21 
最佳回答
0
bluejq发布于2015-9-10 16:21(编辑于 2023-9-6 09:34)
555
  • HaiBao HaiBao

    过滤后反而更慢了,你查看一下过滤字段是否加索引!
    回复
    2015-09-10 12:54 
最佳回答
0
bluejq发布于2015-9-10 17:00(编辑于 2023-9-6 09:34)
555
最佳回答
0
2010带你飞发布于2015-9-11 19:22(编辑于 2023-9-6 09:34)
555
最佳回答
0
传说哥发布于2015-10-7 20:41(编辑于 2023-9-6 09:34)
555
  • 0关注人数
  • 877浏览人数
  • 最后回答于:2015-10-7 20:41
    活动推荐 更多
    热门课程 更多
    返回顶部