diff --git a/core/lib/Drupal/Core/Cache/DatabaseBackend.php b/core/lib/Drupal/Core/Cache/DatabaseBackend.php
index b1144e4..48018b1 100644
--- a/core/lib/Drupal/Core/Cache/DatabaseBackend.php
+++ b/core/lib/Drupal/Core/Cache/DatabaseBackend.php
@@ -202,6 +202,38 @@ protected function doSet($cid, $data, $expire, $tags) {
    * {@inheritdoc}
    */
   public function setMultiple(array $items) {
+    $values = array();
+
+    foreach ($items as $cid => $item) {
+      $item += array(
+        'expire' => CacheBackendInterface::CACHE_PERMANENT,
+        'tags' => array(),
+      );
+
+      Cache::validateTags($item['tags']);
+      $item['tags'] = array_unique($item['tags']);
+      // Sort the cache tags so that they are stored consistently in the DB.
+      sort($item['tags']);
+
+      $fields = array(
+        'cid' => $cid,
+        'expire' => $item['expire'],
+        'created' => round(microtime(TRUE), 3),
+        'tags' => implode(' ', $item['tags']),
+        'checksum' => $this->checksumProvider->getCurrentChecksum($item['tags']),
+      );
+
+      if (!is_string($item['data'])) {
+        $fields['data'] = serialize($item['data']);
+        $fields['serialized'] = 1;
+      }
+      else {
+        $fields['data'] = $item['data'];
+        $fields['serialized'] = 0;
+      }
+      $values[] = $fields;
+    }
+
     // Use a transaction so that the database can write the changes in a single
     // commit.
     $transaction = $this->connection->startTransaction();
@@ -213,37 +245,11 @@ public function setMultiple(array $items) {
 
       $query = $this->connection
         ->insert($this->bin)
-        ->fields(array('cid', 'data', 'expire', 'created', 'serialized', 'tags', 'checksum'));
-
-      foreach ($items as $cid => $item) {
-        $item += array(
-          'expire' => CacheBackendInterface::CACHE_PERMANENT,
-          'tags' => array(),
-        );
-
-        Cache::validateTags($item['tags']);
-        $item['tags'] = array_unique($item['tags']);
-        // Sort the cache tags so that they are stored consistently in the DB.
-        sort($item['tags']);
-
-        $fields = array(
-          'cid' => $cid,
-          'expire' => $item['expire'],
-          'created' => round(microtime(TRUE), 3),
-          'tags' => implode(' ', $item['tags']),
-          'checksum' => $this->checksumProvider->getCurrentChecksum($item['tags']),
-        );
-
-        if (!is_string($item['data'])) {
-          $fields['data'] = serialize($item['data']);
-          $fields['serialized'] = 1;
-        }
-        else {
-          $fields['data'] = $item['data'];
-          $fields['serialized'] = 0;
-        }
-
-        $query->values($fields);
+        ->fields(array('cid', 'expire', 'created', 'tags', 'checksum', 'data', 'serialized'));
+      foreach ($values as $fields) {
+        // Only pass the values to values since the order of $fields matches the
+        // order of the insert fields.
+        $query->values(array_values($fields));
       }
 
       $query->execute();
