Mysql查询永远占用并且吃太多ram

时间:2017-09-21 02:11:06

标签: mysql database left-join

以下是我尝试加载列的查询:Imc_code,salesman_name,sales_man_code和InvoiceTotal。我尝试用左连接来做,但随着我的数据变得越来越大,我的代码变得越来越慢。现在我的数据已接近300万,我甚至无法使用下面的代码加载单个数据。

目前正在使用localhost和表同时使用InnoDb和Myisam引擎。

我还在我的查询上运行了解释,只显示了20行: enter image description here enter image description here

SELECT 
      pref_salesman.imc_code , pref_salesman.salesman_name, 
      pref_salesman.salesman_code, pref_debtor_trans.branch_code, 
      SUM(pref_debtor_trans.ov_amount + pref_debtor_trans.ov_discount) AS InvoiceTotal

FROM 
    pref_debtor_trans LEFT JOIN pref_voided v ON 
    v.type = pref_debtor_trans.type and v.id=pref_debtor_trans.trans_no,
    pref_debtors_master, pref_sales_orders, pref_cust_branch,pref_salesman 

WHERE 
    pref_sales_orders.order_no=pref_debtor_trans.order_
    AND pref_sales_orders.branch_code=pref_cust_branch.branch_code
    AND pref_cust_branch.salesman=pref_salesman.salesman_code
    AND pref_debtor_trans.debtor_no=pref_debtors_master.debtor_no
    AND pref_debtor_trans.tran_date >= '01-01-2017'

0 个答案:

没有答案
相关问题