zoukankan      html  css  js  c++  java
  • sql执行速度优化

    1. 查找最新的主单对应的子单的sum

    1. 版本一 执行十几秒没有出现结果
    select sum(c.putaway_qty),a.consignment_no,c.sku_code 
    from odoo_dsf_inbound_order_info a 
    inner join 
    (select max(id) as id from odoo_dsf_inbound_order_info group by consignment_no) b on b.id=a.id 
    inner join odoo_dsf_inbound_detail_sku_info c on a.consignment_no=c.consignment_no and a.serial_number=c.serial_number 
    where a.status='C' and c.putaway_qty !=0  group by a.consignment_no,c.sku_code 

    2. 版本二 400万不到的数据,修改之后6秒出结果
    select sum(c.putaway_qty),
    a.consignment_no,c.sku_code
    from odoo_dsf_inbound_order_info a
    inner join
    (select max(id) as id from odoo_dsf_inbound_order_info group by consignment_no) b on b.id=a.id
    inner join (select * from odoo_dsf_inbound_detail_sku_info limit 4000000) c on a.consignment_no=c.consignment_no and a.serial_number=c.serial_number
    where a.status='C' and c.putaway_qty !=0 group by a.consignment_no,c.sku_code

    3. 版本三 因为我们是一次性任务,而且只要结果就可以,使用临时表(1秒左右)
    ---将最新的ID存在临时表
    drop table if exists temp_m;
    select max(id) as id into temp temp_m from odoo_dsf_inbound_order_info group by consignment_no;

    ---查询结果
    select sum(c.putaway_qty),
    a.consignment_no,c.sku_code -- INTO TEMP rrrr
    from odoo_dsf_inbound_order_info a
    inner join temp_m on temp_m.id=a.id
    inner join odoo_dsf_inbound_detail_sku_info c on a.consignment_no=c.consignment_no and a.serial_number=c.serial_number
    where a.status='C' and c.putaway_qty !=0 group by a.consignment_no,c.sku_code;


  • 相关阅读:
    对话框中设置静态文本框字体及颜色
    UVA 10250 The Other Two Trees(几何)
    UVA 113 Power of Cryptography(数学)
    VC++设置半透明界面
    UVA 10474 Where is the Marble?
    UVA 123 Searching Quickly(分离单词)
    为对话框在标题栏和任务栏关联图标
    UVA 152 Tree's a Crowd
    UVA 156 Ananagrams
    UVA 299 Train Swapping(冒泡排序)
  • 原文地址:https://www.cnblogs.com/JackShi/p/14151361.html
Copyright © 2011-2022 走看看