jeudi 13 août 2015

Query SQL runs slow with group by in MySQL

I have a sql below, it runs about 30 mins, which is too long for me.

SELECT LPP.learning_project_pupilID, SL.serviceID, MAX(LPPO.start_date), SUM(LPPOT.license_mode_value) totalAssignedLicenses
      FROM t_services_licenses SL 
      INNER JOIN t_pupils_offers_services POS ON POS.service_licenseID = SL.service_licenseID 
      INNER JOIN j_learning_projects_pupils_offers LPPO ON LPPO.learning_project_pupil_offerID = POS.learning_project_pupil_offerID
      INNER JOIN j_learning_projects_pupils LPP ON LPPO.learning_project_pupilID = LPP.learning_project_pupilID
      INNER JOIN j_learning_projects_pupils_offers_tracking LPPOT ON LPPOT.pupil_offer_serviceID = POS.pupil_offer_serviceID
      INNER JOIN t_filters_items FI ON FI.itemID = LPP.learning_project_pupilID_for_filter_join  
      WHERE FI.filterID = '4dce2235-aafd-4ba2-b248-c137ad6ce8ca' 
      AND SL.serviceID IN ('OnlineConversationClasses', 'TwentyFourSeven')
      GROUP BY LPP.learning_project_pupilID, SL.serviceID

I have viewed the profile result, "copying temp data " wasted almost all the time. I know the reason is caused by "group by" functionality, So I did some changes below to verify it: I removed the MAX, SUM functions as well as the Group By sql and ran it, the time is only cost about 40 seconds, which is ok for us. So here , I want to know, if there are some other methods to make above sql execute much more faster?

more info, you can find here: http://ift.tt/1IMaMjk



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire