Details
-
Type: Improvement
-
Status: Done/Fixed
-
Priority: Trivial
-
Resolution: Fixed/Completed
-
Affects Version/s: 3.3.5
-
Fix Version/s: 3.4.alpha
-
Component/s: CiviReport
-
Labels:None
Description
The query run on the commission report detail is REALLY slow - devel shows 69,000 milliseconds
I fixed it in my custom-report-based-on-this-report by removing the ordinality function out of my report. However, the main one could be fixed by only including the 'ordinality join' (approx line 252 of CRM_Report_Form_Contribute_Detail) if ordinality is set as a display or filter
QUERY
SELECT SQL_CALC_FOUND_ROWS contact_civireport.display_name as civicrm_contact_display_name, contact_civireport.id as civicrm_contact_id, email_civireport.email as civicrm_email_email, phone_civireport.phone as civicrm_phone_phone, address_civireport.country_id as civicrm_address_country_id, contribution_civireport.contribution_type_id as civicrm_contribution_contribution_type_id, contribution_civireport.receive_date as civicrm_contribution_receive_date, SUM(contribution_civireport.total_amount) as civicrm_contribution_total_amount_sum FROM civicrm_contact contact_civireport INNER JOIN civicrm_contribution contribution_civireport ON contact_civireport.id = contribution_civireport.contact_id AND contribution_civireport.is_test = 0 INNER JOIN (SELECT c.id, IF(COUNT(oc.id) = 0, 0, 1) AS ordinality FROM civicrm_contribution c LEFT JOIN civicrm_contribution oc ON c.contact_id = oc.contact_id AND oc.receive_date < c.receive_date GROUP BY c.id) cordinality_civireport ON cordinality_civireport.id = contribution_civireport.id LEFT JOIN civicrm_phone phone_civireport ON (contact_civireport.id = phone_civireport.contact_id AND phone_civireport.is_primary = 1) LEFT JOIN civicrm_address address_civireport ON contact_civireport.id = address_civireport.contact_id AND address_civireport.is_primary = 1 LEFT JOIN civicrm_email email_civireport ON contact_civireport.id = email_civireport.contact_id AND email_civireport.is_primary = 1WHERE ( contribution_civireport.contribution_type_id IN (12) ) AND ( contribution_civireport.contribution_status_id IN (1) ) AND contact_civireport.is_deleted = 0 GROUP BY contact_civireport.id, contribution_civireport.id ORDER BY contact_civireport.id LIMIT 0, 50
EXPLAIN RESULTS
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 161361 Using temporary; Using filesort
1 PRIMARY contribution_civireport eq_ref PRIMARY,index_contribution_status,FK_civicrm_contr... PRIMARY 4 cordinality_civireport.id 1 Using where
1 PRIMARY contact_civireport eq_ref PRIMARY,index_is_deleted,dedupe_index_id PRIMARY 4 mprc_pb.contribution_civireport.contact_id 1 Using where
1 PRIMARY phone_civireport ref index_is_primary,FK_civicrm_phone_contact_id FK_civicrm_phone_contact_id 5 mprc_pb.contribution_civireport.contact_id 1
1 PRIMARY address_civireport ref index_is_primary,FK_civicrm_address_contact_id FK_civicrm_address_contact_id 5 mprc_pb.contact_civireport.id 1
1 PRIMARY email_civireport ref index_is_primary,FK_civicrm_email_contact_id FK_civicrm_email_contact_id 5 mprc_pb.contact_civireport.id 1
2 DERIVED c index NULL PRIMARY 4 NULL 160735
2 DERIVED oc ref received_date,FK_civicrm_contribution_contact_id,r... FK_civicrm_contribution_contact_id 4 mprc_pb.c.contact_id 2