CRM-17775 fix indexes on table civicrm_financial_item
authoreileen <emcnaughton@wikimedia.org>
Tue, 2 Feb 2016 23:42:52 +0000 (12:42 +1300)
committereileen <emcnaughton@wikimedia.org>
Wed, 3 Feb 2016 10:37:21 +0000 (23:37 +1300)
CRM/Upgrade/Incremental/php/FourSeven.php
xml/schema/Financial/FinancialItem.xml

index da42435c132bd65caba3ba2b90656b2ce398d06c..a2e49c35cdd8a0e26ce50ff4bd57dd7b06825983 100644 (file)
@@ -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;
+  }
+
 }
index 0af6ec7f19339dc836faacd5b4f9954f0fe9a2f5..fbda7e565e4cf8ea209fdb42d0de0f296ee7b194 100644 (file)
     <fieldName>id</fieldName>
     <unique>true</unique>
     <add>4.3</add>
+    <drop>4.7</drop>
   </index>
   <index>
     <name>IX_created_date</name>
     <fieldName>entity_table</fieldName>
     <fieldName>entity_id</fieldName>
     <add>4.3</add>
+    <drop>4.7</drop>
   </index>
   <index>
-    <name>IX_entity</name>
-    <fieldName>entity_table</fieldName>
+    <name>index_entity_id_entity_table</name>
     <fieldName>entity_id</fieldName>
-    <add>4.3</add>
+    <fieldName>entity_table</fieldName>
+    <add>4.7</add>
   </index>
 </table>