diff --git a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php
index 871ebe95d44..3fd68e42164 100644
--- a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php
+++ b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php
@@ -760,7 +760,7 @@ public function getRootPathIds($id) {
     $subquery->fields($this->table, ['p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9']);
     $subquery->condition('id', $id);
     $result = current($subquery->execute()->fetchAll(\PDO::FETCH_ASSOC));
-    $ids = array_filter($result);
+    $ids = $result ? array_filter($result) : NULL;
     if ($ids) {
       $query = $this->connection->select($this->table, NULL, $this->options);
       $query->fields($this->table, ['id']);
