CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Strange MySQL-Query from CiviCRM
Pages: [1]

Author Topic: Strange MySQL-Query from CiviCRM  (Read 853 times)

Rince

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
Strange MySQL-Query from CiviCRM
February 10, 2010, 03:31:00 pm
Hi,

we have a userbase of around 12000 people in our CiviCRM-System and I the one guy who tries to find out why sometimes the performance of our system is quite bad - some selects just take more than just some minutes.

One of the queries I found disturbing is the following one:


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-101`
    ON contact_a.id = `civicrm_group_contact-101`.contact_id   
  LEFT JOIN civicrm_group_contact `civicrm_group_contact-102`
    ON contact_a.id = `civicrm_group_contact-102`.contact_id   
  LEFT JOIN civicrm_group_contact `civicrm_group_contact-46`
    ON contact_a.id = `civicrm_group_contact-46`.contact_id   
  LEFT JOIN civicrm_group_contact `civicrm_group_contact-60`
    ON contact_a.id = `civicrm_group_contact-60`.contact_id   
  LEFT JOIN civicrm_group_contact `civicrm_group_contact-6`
    ON contact_a.id = `civicrm_group_contact-6`.contact_id   
  LEFT JOIN civicrm_group_contact `civicrm_group_contact-94`
   ON contact_a.id = `civicrm_group_contact-94`.contact_id   
  LEFT JOIN civicrm_group_contact `civicrm_group_contact-95`
    ON contact_a.id = `civicrm_group_contact-95`.contact_id   
  LEFT JOIN civicrm_group_contact `civicrm_group_contact-97`
    ON contact_a.id = `civicrm_group_contact-97`.contact_id   
  LEFT JOIN civicrm_group_contact `civicrm_group_contact-99`
    ON contact_a.id = `civicrm_group_contact-99`.contact_id   
  LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_6`
    ON contact_a.id = `civicrm_group_contact_cache_6`.contact_id   
WHERE 
  (
   (
    ( `civicrm_group_contact-6`.group_id IN ( 6 )
     AND
      `civicrm_group_contact-6`.status IN ("Added" )
     )
     OR
     ( `civicrm_group_contact_cache_6`.group_id = 6
     )
    )
   ) 
   AND 
   ( 
    ( `civicrm_group_contact-6`.group_id IN ( 6 )
    AND `civicrm_group_contact-6`.status IN ("Added")
   ) 
   OR 
   ( `civicrm_group_contact-46`.group_id IN ( 46 )
   AND `civicrm_group_contact-46`.status IN ("Added")
   ) 
  OR 
   ( `civicrm_group_contact-60`.group_id IN ( 60 )
   AND `civicrm_group_contact-60`.status IN ("Added")
  ) OR ( `civicrm_group_contact-94`.group_id IN ( 94 )
  AND `civicrm_group_contact-94`.status IN ("Added") ) 
  OR  ( `civicrm_group_contact-95`.group_id IN ( 95 )
  AND `civicrm_group_contact-95`.status IN ("Added") ) 
  OR  ( `civicrm_group_contact-97`.group_id IN ( 97 )
  AND `civicrm_group_contact-97`.status IN ("Added") ) 
  OR  ( `civicrm_group_contact-99`.group_id IN ( 99 )
  AND `civicrm_group_contact-99`.status IN ("Added") )   
  OR  ( `civicrm_group_contact-101`.group_id IN ( 101 )
  AND `civicrm_group_contact-101`.status IN ("Added") ) 
  OR  ( `civicrm_group_contact-102`.group_id IN ( 102 )
  AND `civicrm_group_contact-102`.status IN ("Added") )  );


I am not an expert on CiviCRM, I just have a test-account to check whether I can find some bugs, I just found this query by checking the processlist of mysql. I don't know how to "get" this via CiviCRM-Frontend-Access.
But: What is the reason for this statement? there are quite a lot of joins, but it doesn't seem to be needed - since all you are asking for is the following:


SELECT DISTINCT UPPER(LEFT(contact_a.sort_name, 1)) as sort_name 
FROM civicrm_contact contact_a;


or do I miss something there?
And if I am right, where could I "cut" the statement to that small part? Since that goes very fast with MySQL then... :-)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Strange MySQL-Query from CiviCRM
February 10, 2010, 04:22:22 pm

what version are u on?

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Rince

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
Re: Strange MySQL-Query from CiviCRM
February 10, 2010, 09:37:05 pm
This is CiviCRM 2.1.4.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Strange MySQL-Query from CiviCRM
February 10, 2010, 09:42:32 pm

u should upgrade. we've optimized the search queries a fair bit since that time

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Strange MySQL-Query from CiviCRM

This forum was archived on 2017-11-26.