Mysql Optimization suggestion for large table

后端 未结 2 811
天命终不由人
天命终不由人 2021-01-29 09:18

i want to optimize this query,

select  location_id, dept_id,
        round(sum(sales),0), sum(qty),
        count(distinct tran_id),
        now()
    from  tra         


        
2条回答
  •  误落风尘
    2021-01-29 09:55

    For this query:

    select location_id, dept_id,
           round(sum(sales), 0), sum(qty), count(distinct tran_id),
           now()
    from tran_sales
    where tran_date <= '2016-12-24'
    group by location_id, dept_id;
    

    There is not much you can do. One attempt would be a covering index: (tran_date, location_id, dept_id, sales, qty), but I don't think that will help much.

提交回复
热议问题