Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Trivial
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.6.6
-
Fix Version/s: 4.6.8
-
Component/s: None
-
Labels:None
-
Documentation Required?:None
-
Funding Source:Contributed Code
Description
On large databases the activity report is a server killer as it uses an unindexed join onto the option value table (quick refresher option_value.value is a varchar, activity_type_id is an int - hence this join is not indexed & should be avoided).
Sample query
SELECT activity_civireport.id as civicrm_activity_id, activity_civireport.activity_type_id as civicrm_activity_activity_type_id, activity_civireport.subject as civicrm_activity_subject, activity_civireport.activity_date_time as civicrm_activity_activity_date_time, activity_civireport.status_id as civicrm_activity_activity_status_id ,
activity_source_civireport.display_name as added_by FROM
civicrm_activity activity_civireport
LEFT JOIN civicrm_activity_contact civicrm_activity_target ON
activity_civireport.id = civicrm_activity_target.activity_id AND
civicrm_activity_target.record_type_id = 3
LEFT JOIN civicrm_activity_contact civicrm_activity_assignment ON
activity_civireport.id = civicrm_activity_assignment.activity_id AND civicrm_activity_assignment.record_type_id = 1
LEFT JOIN civicrm_activity_contact civicrm_activity_source
ON activity_civireport.id = civicrm_activity_source.activity_id AND
civicrm_activity_source.record_type_id = 2
LEFT JOIN civicrm_contact activity_target_civireport ON
civicrm_activity_target.contact_id = activity_target_civireport.id
LEFT JOIN civicrm_contact activity_assignment_civireport ON
civicrm_activity_assignment.contact_id = activity_assignment_civireport.id
LEFT JOIN civicrm_contact activity_source_civireport ON
civicrm_activity_source.contact_id = activity_source_civireport.id
LEFT JOIN civicrm_option_value ON
( activity_civireport.activity_type_id = civicrm_option_value.value )
LEFT JOIN civicrm_option_group ON
civicrm_option_group.id = civicrm_option_value.option_group_id
LEFT JOIN civicrm_case_activity ON
civicrm_case_activity.activity_id = activity_civireport.id
LEFT JOIN civicrm_case ON
civicrm_case_activity.case_id = civicrm_case.id
LEFT JOIN civicrm_case_contact ON
civicrm_case_contact.case_id = civicrm_case.id
WHERE ( civicrm_activity_source.contact_id IN (255387,255459,255460,255461,255462,255463,255464,255465,255466,255467) OR
civicrm_activity_target.contact_id IN (255387,255459,255460,255461,255462,255463,255464,255465,255466,255467) OR
civicrm_activity_assignment.contact_id IN (255387,255459,255460,255461,255462,255463,255464,255465,255466,255467) OR
civicrm_case_contact.contact_id IN (255387,255459,255460,255461,255462,255463,255464,255465,255466,255467) ) AND
civicrm_option_group.name = 'activity_type' AND
activity_civireport.is_test = 0 AND
(( civicrm_option_value.component_id IS NULL OR
civicrm_option_value.component_id IN (1, 2, 3, 4, 6, 8) ))
GROUP BY activity_civireport.id
ORDER BY activity_civireport.activity_date_time desc