2011-10-10 95 views
0

我有一個包含子查詢的批量查詢。當我在開發服務器上運行它時,我的查詢工作正常,但是當我在實時服務器上嘗試它時,查詢花費太多時間來生成輸出。我認爲這是因爲活服務器上的大數據。任何人都可以幫助我如何索引MySQL的查詢,以減少時間執行。在MySQL上建立索引

這裏是我的查詢:

SELECT prd.fldemployeeno AS Empno, 
     (SELECT fldemployeename FROM tblprofile prf WHERE prf.fldemployeeno = prd.fldemployeeno LIMIT 0,1) AS Empname, 
     '01' AS `Week`, 
     COUNT(DISTINCT isAud.fldid) AuditedFiles, 
     COUNT(qua.seqid) ErrorCount, 
     COUNT(DISTINCT qua.fldid) OrdersWithError 
    FROM tbldownloadITL dwn 
INNER JOIN tblproductionITL prd 
    ON dwn.fldid = prd.fldglobalid 
INNER JOIN (SELECT p.fldemployeeno,fldglobalid,p.fldstarttime,COALESCE(q.fldstarttime,p.fldstarttime) `AuditDate` 
       FROM tblproductionitl p 
       LEFT JOIN tblqualityaudit q 
       ON p.fldemployeeno=q.fldemployeeno 
       AND p.fldstarttime=q.fldprodstarttime 
       AND p.fldglobalid=q.fldid 
       WHERE p.fldprojectgroup='PROJGROUP') temp 
    ON prd.fldglobalid=temp.fldglobalid 
    AND prd.fldemployeeno=temp.fldemployeeno 
    AND prd.fldstarttime=temp.fldstarttime 
INNER JOIN tblisauditedITL isAud 
USING (fldid) 
    LEFT JOIN tblqualityaudit qua 
    ON qua.fldid = dwn.fldid 
    AND qua.fldbusunit = dwn.fldbusunit 
    AND qua.fldprojectGroup = dwn.fldprojectGroup 
    AND qua.fldemployeeno = prd.fldemployeeno 
    AND qua.fldprodstarttime = prd.fldstarttime 
    AND qua.flderrorstatus != 'NOT ERROR' 
    LEFT JOIN tblerrorcategory 
USING (flderrorcategoryid) 
    LEFT JOIN tblerrortypes 
USING (flderrortypeid) 
WHERE dwn.fldbusunit = 'BUSUNIT' 
    AND dwn.fldprojectGroup = 'PROJGROUP' 
    AND temp.AuditDate BETWEEN '2011-07-29 00:00:00' AND '2011-07-29 23:59:59' 
GROUP BY prd.fldemployeeno 
ORDER BY Empname 

這裏也是查詢的描述:

enter image description here

+1

上''是什麼可能速度變慢了很多臨時/文件排序。我很難看出你的sql的哪個部分導致了這一點。 – imm

回答

1

我建議在服務器上安裝獅身人面像,如果你有訪問。這樣,您可以在指尖獲取索引資源以進行極快搜索,除此之外,您還可以添加所謂'delta'索引的執行,以便實時更新mysql數據庫。它是高度可定製的。希望這會幫助你。

http://sphinxsearch.com/