简体   繁体   中英

Indexing on MySQL

I have a bulk query with subquery. My query works fine when I run it on development server, but when I've try it pn the live server, the query takes too much time to produce an output. I think it's because of a big data on the live server. Can anyone help me on how to index query on MySQL so that it will lessen the time execution.

Here is my query:

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

Here is also the description of the query:

在此处输入图片说明

I would suggest installing Sphinx on the your server if you have the access. That way you can have an indexed resource at your finger tips for extremely fast searching, on top of that you can add the execution of what is called a 'delta' index to allow for real time updating of your mysql database. It is highly customizable. Hopefully this will help you out.

http://sphinxsearch.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM