diff --git a/core/modules/views/src/Plugin/views/query/Sql.php b/core/modules/views/src/Plugin/views/query/Sql.php
index 7ee7316..0a238e5 100644
--- a/core/modules/views/src/Plugin/views/query/Sql.php
+++ b/core/modules/views/src/Plugin/views/query/Sql.php
@@ -1579,17 +1579,14 @@ public function getCacheMaxAge() {
    * @return \Drupal\Core\Entity\EntityInterface[]
    */
   protected function getAllEntities() {
-    $entities = [];
     foreach ($this->view->result as $row) {
       if ($row->_entity) {
-        $entities[] = $row->_entity;
+        yield $row->_entity;
       }
       foreach ($row->_relationship_entities as $entity) {
-        $entities[] = $entity;
+        yield $entity;
       }
     }
-
-    return $entities;
   }
 
   public function addSignature(ViewExecutable $view) {
