Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-12668

Search by group type creates inefficient query

    Details

    • Documentation Required?:
      None
    • Funding Source:
      Needs Funding

      Description

      Search by group type creates a query with lots of LEFT JOINs into the group_contact_cache which doesn't complete in a timely fashion on our site.

      Example query:
      SELECT DISTINCT UPPER(LEFT(contact_a.sort_name, 1)) as sort_name FROM civicrm_contact contact_a LEFT JOIN civicrm_group_contact `civicrm_group_contact-584,454,583,749,743,38,50,332,8,9,22,698,657,681,32,67,172,570,636,637,48,416,10,16,18,20,45,716,34,184,173,210,136,360,751,11,302,23,87,280,176,178,121,40,150,52,53,62,59,58,192,201,194,191,189,143,120,138,65,66,73,72,85,116,117,750,346,68,170,124,6,206,347,211,319,126,137,212,144,683,715,139,633,634,149,193,153,215,348,129,154,534,535,163,536,165,162,167` ON contact_a.id = `civicrm_group_contact-584,454,583,749,743,38,50,332,8,9,22,698,657,681,32,67,172,570,636,637,48,416,10,16,18,20,45,716,34,184,173,210,136,360,751,11,302,23,87,280,176,178,121,40,150,52,53,62,59,58,192,201,194,191,189,143,120,138,65,66,73,72,85,116,117,750,346,68,170,124,6,206,347,211,319,126,137,212,144,683,715,139,633,634,149,193,153,215,348,129,154,534,535,163,536,165,162,167`.contact_id LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_137` ON contact_a.id = `civicrm_group_contact_cache_137`.contact_id LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_139` ON contact_a.id = `civicrm_group_contact_cache_139`.contact_id LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_215` ON contact_a.id = `civicrm_group_contact_cache_215`.contact_id LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_22` ON contact_a.id = `civicrm_group_contact_cache_22`.contact_id LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_319` ON contact_a.id = `civicrm_group_contact_cache_319`.contact_id LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_348` ON contact_a.id = `civicrm_group_contact_cache_348`.contact_id LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_48` ON contact_a.id = `civicrm_group_contact_cache_48`.contact_id LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_52` ON contact_a.id = `civicrm_group_contact_cache_52`.contact_id LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_570` ON contact_a.id = `civicrm_group_contact_cache_570`.contact_id LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_584` ON contact_a.id = `civicrm_group_contact_cache_584`.contact_id LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_58` ON contact_a.id = `civicrm_group_contact_cache_58`.contact_id LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_65` ON contact_a.id = `civicrm_group_contact_cache_65`.contact_id LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_72` ON contact_a.id = `civicrm_group_contact_cache_72`.contact_id LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_8` ON contact_a.id = `civicrm_group_contact_cache_8`.contact_id
      LEFT JOIN civicrm_value_woodies_info_2 ON civicrm_value_woodies_info_2.entity_id = contact_a.id WHERE ( ( ( `civicrm_group_contact-584,454,583,749,743,38,50,332,8,9,22,698,657,681,32,67,172,570,636,637,48,416,10,16,18,20,45,716,34,184,173,210,136,360,751,11,302,23,87,280,176,178,121,40,150,52,53,62,59,58,192,201,194,191,189,143,120,138,65,66,73,72,85,116,117,750,346,68,170,124,6,206,347,211,319,126,137,212,144,683,715,139,633,634,149,193,153,215,348,129,154,534,535,163,536,165,162,167`.group_id IN ( 584,454,583,749,743,38,50,332,8,9,22,698,657,681,32,67,172,570,636,637,48,416,10,16,18,20,45,716,34,184,173,210,136,360,751,11,302,23,87,280,176,178,121,40,150,52,53,62,59,58,192,201,194,191,189,143,120,138,65,66,73,72,85,116,117,750,346,68,170,124,6,206,347,211,319,126,137,212,144,683,715,139,633,634,149,193,153,215,348,129,154,534,535,163,536,165,162,167 ) AND `civicrm_group_contact-584,454,583,749,743,38,50,332,8,9,22,698,657,681,32,67,172,570,636,637,48,416,10,16,18,20,45,716,34,184,173,210,136,360,751,11,302,23,87,280,176,178,121,40,150,52,53,62,59,58,192,201,194,191,189,143,120,138,65,66,73,72,85,116,117,750,346,68,170,124,6,206,347,211,319,126,137,212,144,683,715,139,633,634,149,193,153,215,348,129,154,534,535,163,536,165,162,167`.status IN ("Added") ) OR ( `civicrm_group_contact_cache_8`.group_id = 8 OR `civicrm_group_contact_cache_22`.group_id = 22 OR `civicrm_group_contact_cache_48`.group_id = 48 OR `civicrm_group_contact_cache_52`.group_id = 52 OR `civicrm_group_contact_cache_58`.group_id = 58 OR `civicrm_group_contact_cache_65`.group_id = 65 OR `civicrm_group_contact_cache_72`.group_id = 72 OR `civicrm_group_contact_cache_137`.group_id = 137 OR `civicrm_group_contact_cache_139`.group_id = 139 OR `civicrm_group_contact_cache_215`.group_id = 215 OR `civicrm_group_contact_cache_319`.group_id = 319 OR `civicrm_group_contact_cache_348`.group_id = 348 OR `civicrm_group_contact_cache_570`.group_id = 570 OR `civicrm_group_contact_cache_584`.group_id = 584 ) ) AND civicrm_value_woodies_info_2.membership_type_13 = 'adult-main' ) AND (contact_a.is_deleted = 0) ORDER BY UPPER(LEFT(contact_a.sort_name, 1)) asc

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              jamessharpe James Sharpe
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: