diff --git a/core/includes/gettext.inc b/core/includes/gettext.inc
index 18c27ea..121373b 100644
--- a/core/includes/gettext.inc
+++ b/core/includes/gettext.inc
@@ -461,7 +461,8 @@ function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NUL
  *   The string ID of the existing string modified or the new string added.
  */
 function _locale_import_one_string_db(&$report, $langcode, $context, $source, $translation, $location, $mode) {
-  $lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = :context", array(':source' => $source, ':context' => $context))->fetchField();
+  $hashkey = md5($source . "\0" . $context);
+  $lid = db_query("SELECT lid FROM {locales_source} WHERE hashkey = :hashkey", array(':hashkey' => $hashkey))->fetchField();
 
   if (!empty($translation)) {
     // Skip this string unless it passes a check for dangerous code.
@@ -513,6 +514,7 @@ function _locale_import_one_string_db(&$report, $langcode, $context, $source, $t
           'location' => $location,
           'source' => $source,
           'context' => (string) $context,
+          'hashkey' => $hashkey,
         ))
         ->execute();
 
diff --git a/core/includes/locale.inc b/core/includes/locale.inc
index 1f9567b..eceaf61 100644
--- a/core/includes/locale.inc
+++ b/core/includes/locale.inc
@@ -635,7 +635,8 @@ function _locale_parse_js_file($filepath) {
     $string =  implode('', preg_split('~(?<!\\\\)[\'"]\s*\+\s*[\'"]~s', substr($match['string'], 1, -1)));
     $context = implode('', preg_split('~(?<!\\\\)[\'"]\s*\+\s*[\'"]~s', substr($match['context'], 1, -1)));
 
-    $source = db_query("SELECT lid, location FROM {locales_source} WHERE source = :source AND context = :context", array(':source' => $string, ':context' => $context))->fetchObject();
+    $hashkey = md5($string . "\0" . $context);
+    $source = db_query("SELECT lid, location FROM {locales_source} WHERE hashkey = :hashkey", array(':hashkey' => $hashkey))->fetchObject();
     if ($source) {
       // We already have this source string and now have to add the location
       // to the location column, if this file is not yet present in there.
@@ -661,6 +662,7 @@ function _locale_parse_js_file($filepath) {
           'location'  => $filepath,
           'source'    => $string,
           'context'   => $context,
+          'hashkey'   => $hashkey,
         ))
         ->execute();
     }
diff --git a/core/includes/update.inc b/core/includes/update.inc
index 1a2a242..999be65 100644
--- a/core/includes/update.inc
+++ b/core/includes/update.inc
@@ -197,6 +197,24 @@ function update_prepare_d8_language() {
     require_once DRUPAL_ROOT . '/core/modules/language/language.install';
     language_update_8000();
   }
+  // Add 'hashkey' column to 'locales_source' table.
+  if (db_table_exists('locales_source') && !db_field_exists('locales_source', 'hashkey')) {
+    $hashkey_spec = array(
+      'description' => 'An md5 hash of the concatenated string and context. Used for quick lookups.',
+      'type' => 'char',
+      'length' => 32,
+      'not null' => TRUE,
+      'default' => '',
+    );
+    $hashkey_indexes = array(
+      'indexes' => array(
+        'hashkey' => array('hashkey'),
+      ),
+    );
+    db_add_field('locales_source', 'hashkey', $hashkey_spec, $hashkey_indexes);
+    // Drop unneeded index.
+    db_drop_index('locales_source', 'source_context');
+  }
 }
 
 /**
diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install
index 11d1873..d0155e2 100644
--- a/core/modules/locale/locale.install
+++ b/core/modules/locale/locale.install
@@ -147,10 +147,17 @@ function locale_schema() {
         'default' => 'none',
         'description' => 'Version of Drupal, where the string was last used (for locales optimization).',
       ),
+      'hashkey' => array(
+        'description' => 'An md5 hash of the concatenated string and context. Used for quick lookups.',
+        'type' => 'char',
+        'length' => 32,
+        'not null' => TRUE,
+        'default' => '',
+      ),
     ),
     'primary key' => array('lid'),
     'indexes' => array(
-      'source_context' => array(array('source', 30), 'context'),
+      'hashkey' => array('hashkey'),
     ),
   );
 
diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module
index 6b9ab6e..246a118 100644
--- a/core/modules/locale/locale.module
+++ b/core/modules/locale/locale.module
@@ -666,10 +666,10 @@ function locale($string = NULL, $context = NULL, $langcode = NULL) {
   if (!isset($locale_t[$langcode][$context][$string])) {
 
     // We do not have this translation cached, so get it from the DB.
-    $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context", array(
+    $hashkey = md5($string . "\0" . $context);
+    $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.hashkey = :hashkey", array(
       ':language' => $langcode,
-      ':source' => $string,
-      ':context' => (string) $context,
+      ':hashkey' => $hashkey,
     ))->fetchObject();
     if ($translation) {
       // We have the source string at least.
@@ -696,7 +696,8 @@ function locale($string = NULL, $context = NULL, $langcode = NULL) {
         ))
         ->key(array(
           'source' => $string,
-          'context' => (string) $context,
+          'context' => $context,
+          'hashkey' => $hashkey,
         ))
         ->execute();
       $locale_t[$langcode][$context][$string] = TRUE;
@@ -819,6 +820,12 @@ function locale_system_update($components) {
 function locale_js_alter(&$javascript) {
   global $language_interface;
 
+  if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') {
+    // Skip processing for updates because updated code could use updated
+    // database schema probably not compatible with updated processing.
+    return;
+  }
+
   $dir = 'public://' . variable_get('locale_js_directory', 'languages');
   $parsed = variable_get('javascript_parsed', array());
   $files = $new_files = FALSE;
