MySQL查询需要更多时间来执行

时间:2014-01-23 07:13:31

标签: mysql optimization indexing left-join

SELECT 
  gst_journal.*,
  salesmain.TransactionNo 
FROM
  `gst_journal` 
  LEFT JOIN salesmain 
    ON (
      gst_journal.docNo = salesmain.InvoiceNo 
      AND gst_journal.Source = salesmain.Source
    ) 
WHERE (
    MONTH(salesmain.TDate) = '10' 
    AND YEAR(salesmain.TDate) = '2013' 
    AND salesmain.TDate BETWEEN STR_TO_DATE('2013-10-01', '%Y-%m-%d') 
    AND STR_TO_DATE('2013-10-31', '%Y-%m-%d') 
    AND (
      (
        gst_journal.inOutTax = 'OUT' 
        AND gst_journal.taxType IN ('SR', 'GST') 
        AND gst_journal.Source IN ('AR', 'NR', 'BR', 'PR', 'JV', 'CR')
      )
    )
  ) 
  OR (
    MONTH(gst_journal.TDate) = '10' 
    AND YEAR(gst_journal.TDate) = '2013' 
    AND (
      gst_journal.TDate BETWEEN STR_TO_DATE('2013-10-01', '%Y-%m-%d') 
      AND STR_TO_DATE('2013-10-31', '%Y-%m-%d') 
      AND (
        gst_journal.taxType = 'SR' 
        AND gst_journal.Source IN ('BR')
      )
    )
  ) 
ORDER BY gst_journal.Tdate,
  salesmain.TDate ;

此查询正常运行且记录正确,但需要时间运行。 任何人都可以帮助优化时间查询。

由于

0 个答案:

没有答案