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) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Monster SQL Query
Pages: [1]

Author Topic: Monster SQL Query  (Read 421 times)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Monster SQL Query
November 06, 2013, 11:35:39 am
I have a D7/CiviCRM 4.3.5 site with a DB with 37K financial transactions. We found it's executing this query:

Code: [Select]
SELECT civicrm_financial_trxn.id  , civicrm_financial_trxn.payment_instrument_id as payment_method , civicrm_contribution.contact_id as contact_id , civicrm_contribution.id as contributionID , contact_a.sort_name , civicrm_financial_trxn.total_amount as amount , civicrm_financial_trxn.trxn_id as trxn_id , contact_a.contact_type , contact_a.contact_sub_type , civicrm_financial_trxn.trxn_date as transaction_date , name , civicrm_contribution.currency as currency , civicrm_financial_trxn.status_id as status , civicrm_financial_trxn.check_number as check_number
FROM   civicrm_financial_trxn
LEFT JOIN civicrm_entity_financial_trxn ON civicrm_entity_financial_trxn.financial_trxn_id = civicrm_financial_trxn.id
LEFT JOIN civicrm_entity_batch ON civicrm_entity_batch.entity_id = civicrm_financial_trxn.id
LEFT JOIN civicrm_contribution ON civicrm_contribution.id = civicrm_entity_financial_trxn.entity_id
LEFT JOIN civicrm_financial_type ON civicrm_financial_type.id = civicrm_contribution.financial_type_id
LEFT JOIN civicrm_contact contact_a ON contact_a.id = civicrm_contribution.contact_id
LEFT JOIN civicrm_contribution_soft ON civicrm_contribution_soft.contribution_id = civicrm_contribution.id

WHERE   ( civicrm_entity_batch.batch_id IS NULL
        AND civicrm_entity_financial_trxn.entity_table = 'civicrm_contribution')
        ORDER BY transaction_date desc
 LIMIT 0, 10;

and it takes over 300 seconds to execute. I'm guessing it's due to the size of the transactions table, but this is anyhow ridiculous. I'm not sure what page generates this, but can anyone provide any feedback how we can optimize this?
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Monster SQL Query

This forum was archived on 2017-11-26.