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) »
  • Long SQL query - best methods to tune / optimise so this doesn't hang?
Pages: [1]

Author Topic: Long SQL query - best methods to tune / optimise so this doesn't hang?  (Read 1150 times)

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Long SQL query - best methods to tune / optimise so this doesn't hang?
October 03, 2009, 07:12:30 pm
Our CiviCRM install occasionally gets tied up executing queries which are basically a join across many CiviCRM tables followed by a WHERE contact_a.id IN ( [... 36,000 contact IDs ...] )

CiviCRM ends up dropping this to a temporary table, and the queries hang around for a LONG time.

I'd be interested to hear thoughts on where we can attack this so it becomes workable. MySQL tuning? Rewriting CiviCRM's query code (in this case, 36,000 contacts is most of the DB, so perhaps WHERE NOT would be more sensible)?

CiviCRM 2.2.9 / MySQL 5.0.32

Query SQL

EXPLAIN'd:
idselect_typetabletypepossible_keyskeykey_lenrefrowsExtra
1SIMPLEcontact_aindexPRIMARYindex_sort_name387NULL39348Using where; Using temporary
1SIMPLEcivicrm_addressrefindex_is_primary,FK_civicrm_address_contact_idFK_civicrm_address_contact_id5civicrm.contact_a.id1
1SIMPLEcivicrm_countyeq_refPRIMARYPRIMARY4civicrm.civicrm_address.county_id1
1SIMPLEcivicrm_state_provinceeq_refPRIMARYPRIMARY4civicrm.civicrm_address.state_province_id1
1SIMPLEcivicrm_countryeq_refPRIMARYPRIMARY4civicrm.civicrm_address.country_id1
1SIMPLEcivicrm_emailrefindex_is_primary,FK_civicrm_email_contact_idFK_civicrm_email_contact_id5civicrm.contact_a.id1
1SIMPLEcivicrm_phonerefindex_is_primary,FK_civicrm_phone_contact_idFK_civicrm_phone_contact_id5civicrm.contact_a.id1
1SIMPLEcivicrm_imrefindex_is_primary,FK_civicrm_im_contact_idFK_civicrm_im_contact_id5civicrm.contact_a.id1
1SIMPLEcivicrm_group_contactref_or_nullUI_contact_group,group_contact_idxgroup_contact_idx2const94838
1SIMPLEcivicrm_groupeq_refPRIMARYPRIMARY4civicrm.civicrm_group_contact.group_id1
1SIMPLEcivicrm_entity_tagrefUI_contact_id_tag_id,FK_civicrm_entity_tag_contact_idUI_contact_id_tag_id4civicrm.contact_a.id1Using index
1SIMPLEcivicrm_noterefindex_entityindex_entity198const,civicrm.contact_a.id1
1SIMPLEcivicrm_worldregioneq_refPRIMARYPRIMARY4civicrm.civicrm_country.region_id1
1SIMPLEcivicrm_openidrefFK_civicrm_openid_contact_idFK_civicrm_openid_contact_icivicrm.contact_a.id1
1SIMPLEcivicrm_tageq_refPRIMARYPRIMARY4civicrm.civicrm_entity_tag.tag_id1
1SIMPLEoption_group_genderconstUI_nameUI_name194const1Using index
1SIMPLEgenderrefindex_option_group_id_value,FK_civicrm_option_value_option_group_id,index_option_group_id_nameindex_option_group_id_name4civicrm.option_group_gender.id3
1SIMPLEoption_group_greetingconstUI_nameUI_name194const1Using index
1SIMPLEgreeting_typerefindex_option_group_id_value,FK_civicrm_option_value_option_group_id,index_option_group_id_nameFK_civicrm_option_value_option_group_id4civicrm.option_group_greeting.id3
1SIMPLEoption_group_prefixconstUI_nameUI_name194const1Using index
1SIMPLEindividual_prefixrefindex_option_group_id_value,FK_civicrm_option_value_option_group_id,index_option_group_id_nameindex_option_group_id_name4civicrm.option_group_prefix.id3
1SIMPLEoption_group_suffixconstUI_nameUI_name194const1Using index
1SIMPLEindividual_suffixrefindex_option_group_id_value,FK_civicrm_option_value_option_group_id,index_option_group_id_nameFK_civicrm_option_value_option_group_id4civicrm.option_group_suffix.id3
« Last Edit: October 03, 2009, 07:17:58 pm by xurizaemon »
@xurizaemon ā— www.fuzion.co.nz

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: Long SQL query - best methods to tune / optimise so this doesn't hang?
October 04, 2009, 07:37:44 am

this seems to be a bug in the civicrm query generator. Seems like someone is trying to do an "export all" in your case in which case we should basically skip the contact_a.id clause. The query will still take a long time :(

not sure if it is more efficient to throw the 36K conatcts in a table and do an inner join? might be more efficient? wanna experiment with that?

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

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: Long SQL query - best methods to tune / optimise so this doesn't hang?
October 04, 2009, 08:23:38 am
Export all, or possibly a find dupes too. I know that one of our team has been having timeouts with dupe matching, but I don't know if the request which started this particular query off was one of those.

Thanks Lobo. Will look into it ... but have to wait for low-use times to test this in situ, and all the low-use times for the server are high-demand times for Daddy at the moment. Except 4am :S
@xurizaemon ā— www.fuzion.co.nz

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Long SQL query - best methods to tune / optimise so this doesn't hang?

This forum was archived on 2017-11-26.