diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php b/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php
index 2ba6eb6..b3aedd7 100644
--- a/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php
+++ b/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php
@@ -1424,11 +1424,9 @@ function execute(ViewExecutable $view) {
         }
 
         $result = $query->execute();
+        $result->setFetchMode(\PDO::FETCH_CLASS, 'Drupal\views\ResultRow');
 
-        $view->result = array();
-        foreach ($result as $item) {
-          $view->result[] = $item;
-        }
+        $view->result = iterator_to_array($result);
 
         $view->pager->postExecute($view->result);
         if ($view->pager->useCountQuery() || !empty($view->get_total_rows)) {
@@ -1520,12 +1518,6 @@ function loadEntities(&$results) {
       return;
     }
 
-     // Initialize the entity placeholders in $results.
-    foreach ($results as $index => $result) {
-      $results[$index]->_entity = FALSE;
-      $results[$index]->_relationship_entities = array();
-    }
-
     // Assemble a list of entities to load.
     $ids_by_table = array();
     foreach ($entity_tables as $table_alias => $table) {
@@ -1563,7 +1555,12 @@ function loadEntities(&$results) {
       }
 
       foreach ($ids as $index => $id) {
-        $entity = isset($entities[$id]) ? $entities[$id] : FALSE;
+        if (isset($entities[$id])) {
+          $entity = $entities[$id];
+        }
+        else {
+          $entity = NULL;
+        }
 
         if ($relationship_id == 'none') {
           $results[$index]->_entity = $entity;
diff --git a/core/modules/views/lib/Drupal/views/ResultRow.php b/core/modules/views/lib/Drupal/views/ResultRow.php
new file mode 100644
index 0000000..b704d17
--- /dev/null
+++ b/core/modules/views/lib/Drupal/views/ResultRow.php
@@ -0,0 +1,29 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\views\ResultRow.
+ */
+
+namespace Drupal\views;
+
+/**
+ * A class representing a view result row.
+ */
+class ResultRow {
+
+  /**
+   * The entity for this result.
+   *
+   * @var \Drupal\Core\Entity\EntityInterface
+   */
+  public $_entity = NULL;
+
+  /**
+   * An array of relationship entities.
+   *
+   * @var array \Drupal\Core\Entity\EntityInterface[]
+   */
+  public $_relationship_entities = array();
+
+}
