Remove use of LOWER from city & street searches
authoreileen <emcnaughton@wikimedia.org>
Tue, 23 Oct 2018 19:54:54 +0000 (08:54 +1300)
committereileen <emcnaughton@wikimedia.org>
Tue, 23 Oct 2018 23:41:40 +0000 (12:41 +1300)
Adding LOWER to mysql queries makes them slower. lowercasing php strings
breaks under some character sets with some server configs.

CRM/Contact/BAO/Query.php
tests/phpunit/CRM/Contact/BAO/QueryTest.php

index 027d8165dfdf87ad70f24a26c7797ca118b14dc5..c7857ea451b29f1a55a5599d9819a9e2c6720db6 100644 (file)
@@ -2294,8 +2294,7 @@ class CRM_Contact_BAO_Query {
 
         //get the location name
         list($tName, $fldName) = self::getLocationTableName($field['where'], $locType);
-        // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811.
-        $fieldName = "LOWER(`$tName`.$fldName)";
+        $fieldName = "`$tName`.$fldName";
 
         // we set both _tables & whereTables because whereTables doesn't seem to do what the name implies it should
         $this->_tables[$tName] = $this->_whereTables[$tName] = 1;
@@ -2307,8 +2306,7 @@ class CRM_Contact_BAO_Query {
         }
         else {
           if ($op != 'IN' && !is_numeric($value) && !is_array($value)) {
-            // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811.
-            $fieldName = "LOWER({$field['where']})";
+            $fieldName = "{$field['where']}";
           }
           else {
             $fieldName = "{$field['where']}";
@@ -3566,7 +3564,6 @@ WHERE  $smartGroupClause
         $value = "%{$value}%";
       }
       $op = 'LIKE';
-      // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811.
       $this->_where[$grouping][] = self::buildClause('civicrm_address.street_address', $op, $value, 'String');
       $this->_qill[$grouping][] = ts('Street') . " $op '$n'";
     }
index 96c380d3dc69078619c42664590e49afe2b49678..14b9d98c01b068a5f0e798ba1be94a35b033f4a8 100644 (file)
@@ -223,8 +223,8 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase {
     CRM_Core_Config::singleton()->defaultSearchProfileID = 1;
     $this->callAPISuccess('address', 'create', array(
         'contact_id' => $contactID,
-        'city' => 'Cool City',
-        'street_address' => 'Long Street',
+        'city' => 'Cool CITY',
+        'street_address' => 'Long STREET',
         'location_type_id' => 1,
       ));
     $returnProperties = array(
@@ -257,7 +257,7 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase {
   public function getSearchProfileData() {
     return [
       [
-        [['city', '=', 'Cool City', 1, 0]], "civicrm_address.city as `city`", "LOWER(civicrm_address.city) = 'cool city'",
+        [['city', '=', 'Cool City', 1, 0]], "civicrm_address.city as `city`", "civicrm_address.city = 'cool city'",
       ],
       [
         // Note that in the query 'long street' is lower cased. We eventually want to change that & not mess with the vars - it turns out