From 2179c899a4964af41cb65af4eada637e17f1e3bd Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 3 Feb 2016 12:42:52 +1300 Subject: [PATCH] CRM-17775 fix indexes on table civicrm_financial_item --- CRM/Upgrade/Incremental/php/FourSeven.php | 27 +++++++++++++++++++++++ xml/schema/Financial/FinancialItem.xml | 8 ++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/CRM/Upgrade/Incremental/php/FourSeven.php b/CRM/Upgrade/Incremental/php/FourSeven.php index da42435c13..a2e49c35cd 100644 --- a/CRM/Upgrade/Incremental/php/FourSeven.php +++ b/CRM/Upgrade/Incremental/php/FourSeven.php @@ -154,6 +154,15 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base $this->addTask('Add Index to civicrm_contribution creditnote_id field', 'addIndexContributionCreditNoteID'); } + /** + * Upgrade function. + * + * @param string $rev + */ + public function upgrade_4_7_2($rev) { + $this->addTask('Fix Index on civicrm_financial_item combined entity_id + entity_table', 'addCombinedIndexFinancialItemEntityIDEntityType'); + } + /** * CRM-16354 * @@ -427,4 +436,22 @@ FROM `civicrm_dashboard_contact` WHERE 1 GROUP BY contact_id"; return TRUE; } + /** + * CRM-17775 Add correct index for table civicrm_financial_item. + * + * Note that the entity ID should always precede the entity_table as + * it is more unique. This is better for performance and does not cause fallback + * to no index if table it omitted. + * + * @return bool + */ + public function addCombinedIndexFinancialItemEntityIDEntityType() { + CRM_Core_BAO_SchemaHandler::dropIndexIfExists('civicrm_financial_item', 'UI_id'); + CRM_Core_BAO_SchemaHandler::dropIndexIfExists('civicrm_financial_item', 'IX_Entity'); + CRM_Core_BAO_SchemaHandler::createIndexes(array( + 'civicrm_financial_item' => array(array('entity_id', 'entity_table')), + )); + return TRUE; + } + } diff --git a/xml/schema/Financial/FinancialItem.xml b/xml/schema/Financial/FinancialItem.xml index 0af6ec7f19..fbda7e565e 100644 --- a/xml/schema/Financial/FinancialItem.xml +++ b/xml/schema/Financial/FinancialItem.xml @@ -150,6 +150,7 @@ id true 4.3 + 4.7 IX_created_date @@ -166,11 +167,12 @@ entity_table entity_id 4.3 + 4.7 - IX_entity - entity_table + index_entity_id_entity_table entity_id - 4.3 + entity_table + 4.7 -- 2.25.1