码迷,mamicode.com
首页 > 其他好文 > 详细

数据查询读取优化

时间:2016-11-21 18:24:11      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:ati   评估   div   需要   nbsp   use   多表   nat   tin   

主要随着数据的增加,用到in的,消耗时间几何增长。由于在前期测试评估不到位,没有查看具体的代码。测试版数据量跟线上的数据差距很大,一般很难看出。对于涉及多表复杂查询的功能需要特别留意。

 

优化前 线上74.031秒,测试版0.031秒。随着数据量增加而增加。

select *
  from (select "Extent1".*,
               row_number() OVER(ORDER BY ID desc) as "row_number"
          from (select *
                  from (select s.id,
                               s.shipment_no,
                               s.order_no,
                               s.destination,
                               s.estimated_ship_date,
                               s.orig_warehouse_id
                          from ship_shipment s
                         Where is_deleted = 0
                           and not exists
                         (select sst.id
                                  from ship_shipment sst
                                  left join ship_picklist_item spi
                                    on spi.shipment_id = sst.id
                                  left join ship_picklist sp
                                    on sp.id = spi.picklist_id
                                 inner join (select te.type,
                                                   ti.work_effort_id,
                                                   ti.bill_id_to
                                              from trsf_work_effort te
                                             inner join trsf_work_effort_item ti
                                                on ti.work_effort_id = te.id
                                               and te.type = 13
                                             where ti.is_deleted = 0) t
                                    on t.bill_id_to = spi.id
                                 where spi.is_deleted = 0
                                   and sp.pick_type = 3
                                   and sst.id = s.id)
                           and not exists
                         (select pi.shipment_id
                                  from ship_picklist_item pi
                                  left join ship_picklist spp
                                    on spp.id = pi.picklist_id
                                  left join trsf_work_effort twe
                                    on twe.id = pi.work_effort_id
                                 where spp.pick_type = 3
                                   and twe.status != 3
                                   and pi.is_deleted = 0
                                   and pi.shipment_id = s.id
                                 group by pi.shipment_id)) ss
                 Where 1 = 1
                   and id in
                       (select i.shipment_id
                          from ship_picklist_item i
                         inner join ship_picklist sp
                            on sp.id = i.picklist_id
                           and sp.pick_type = 3
                         where i.is_deleted = 0
                         group by i.shipment_id
                        having sum(nvl(i.quantity_picked, 0)) = sum(nvl(i.quantity_sorted, 0)) and sum(nvl(i.quantity_picked, 0)) > 0)
                   and ss.ORIG_WAREHOUSE_ID = 170) "Extent1") "Extent2"
 where "row_number" > 0
   and rownum <= 20

 

优化后:线上0.359秒  测试版:0.047秒

select *
  from (select s.id,
               s.shipment_no,
               s.order_no,
               s.destination,
               s.estimated_ship_date,
               s.orig_warehouse_id
          from ship_shipment s
         Where is_deleted = 0 
           and not exists
         (select sst.id
                  from ship_shipment sst
                  left join ship_picklist_item spi
                    on spi.shipment_id = sst.id
                  left join ship_picklist sp
                    on sp.id = spi.picklist_id
                 inner join (select te.type, ti.work_effort_id, ti.bill_id_to
                              from trsf_work_effort te
                             inner join trsf_work_effort_item ti
                                on ti.work_effort_id = te.id
                               and te.type = 13
                             where ti.is_deleted = 0) t
                    on t.bill_id_to = spi.id
                 where spi.is_deleted = 0
                   and sp.pick_type = 3
                   and sst.id = s.id)
           and not exists (select pi.shipment_id
                  from ship_picklist_item pi
                  left join ship_picklist spp
                    on spp.id = pi.picklist_id
                  left join trsf_work_effort twe
                    on twe.id = pi.work_effort_id
                 where spp.pick_type = 3
                   and twe.status != 3
                   and pi.is_deleted = 0
                   and pi.shipment_id = s.id
                 group by pi.shipment_id)
                 ) ss,
(select i.shipment_id
          from ship_picklist_item i 
         inner join ship_picklist sp
            on sp.id = i.picklist_id
           and sp.pick_type = 3
         where i.is_deleted = 0 
         group by i.shipment_id
        having sum(nvl(i.quantity_picked, 0)) = sum(nvl(i.quantity_sorted, 0)) 
        and sum(nvl(i.quantity_picked, 0)) > 0) spi 
        where ss.id = spi.shipment_id and ss.orig_warehouse_id = 1

 

数据查询读取优化

标签:ati   评估   div   需要   nbsp   use   多表   nat   tin   

原文地址:http://www.cnblogs.com/llvoeto/p/6085954.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!