diff --git a/core/lib/Drupal/Core/Config/Entity/Query/Query.php b/core/lib/Drupal/Core/Config/Entity/Query/Query.php
index 7332680..b29b179 100644
--- a/core/lib/Drupal/Core/Config/Entity/Query/Query.php
+++ b/core/lib/Drupal/Core/Config/Entity/Query/Query.php
@@ -122,6 +122,7 @@ protected function loadRecords() {
 
     // Search the conditions for restrictions on entity IDs.
     $ids = array();
+    $id_condition = NULL;
     if ($this->condition->getConjunction() == 'AND') {
       foreach ($this->condition->conditions() as $condition) {
         if (is_string($condition['field']) && $condition['field'] == $this->entityType->getKey('id')) {
@@ -132,6 +133,9 @@ protected function loadRecords() {
           elseif ($operator == 'IN') {
             $ids = $condition['value'];
           }
+          else {
+            $id_condition = $condition;
+          }
           // We stop at the first restricting condition on ID. In the (weird)
           // case where there are additional restricting conditions, results
           // will be eliminated when the conditions are checked on the loaded
@@ -152,6 +156,41 @@ protected function loadRecords() {
     // If no restrictions on IDs were found, we need to parse all records.
     else {
       $names = $this->configStorage->listAll($prefix);
+      // In case we have an ID condition, try to narrow down the list of config
+      // objects to load.
+      if ($id_condition) {
+        $value = $id_condition['value'];
+        $filter = NULL;
+        switch ($id_condition['operator']) {
+          case '<>':
+            $filter = function ($name) use ($value, $prefix_length) {
+              $id = substr($name, $prefix_length);
+              return $id !== $value;
+              };
+            break;
+          case 'STARTS_WITH':
+            $filter = function ($name) use ($value, $prefix_length) {
+              $id = substr($name, $prefix_length);
+              return strpos($id, $value) === 0;
+            };
+            break;
+          case 'CONTAINS':
+            $filter = function ($name) use ($value, $prefix_length) {
+              $id = substr($name, $prefix_length);
+              return strpos($id, $value) !== FALSE;
+            };
+            break;
+          case 'ENDS_WITH':
+            $filter = function ($name) use ($value, $prefix_length) {
+              $id = substr($name, $prefix_length);
+              return strrpos($id, $value) === strlen($id) - strlen($value);
+            };
+            break;
+        }
+        if ($filter) {
+          $names = array_filter($names, $filter);
+        }
+      }
     }
 
     // Load the corresponding records.
