diff --git a/src/Plugin/search_api/tracker/Basic.php b/src/Plugin/search_api/tracker/Basic.php
index dcf5feb5..f122fbf4 100644
--- a/src/Plugin/search_api/tracker/Basic.php
+++ b/src/Plugin/search_api/tracker/Basic.php
@@ -196,10 +196,11 @@ class Basic extends TrackerPluginBase implements PluginFormInterface {
       $select->condition('datasource', $datasource_id);
     }
     $select->condition('sai.status', $this::STATUS_NOT_INDEXED, '=');
-    $lifo = $this->configuration['indexing_order'] === 'lifo';
-    $select->orderBy('sai.changed', $lifo ? 'DESC' : 'ASC');
+    // Use the same direction for both sorts to avoid performance problems.
+    $order = $this->configuration['indexing_order'] === 'lifo' ? 'DESC' : 'ASC';
+    $select->orderBy('sai.changed', $order);
     // Add a secondary sort on item ID to make the order completely predictable.
-    $select->orderBy('sai.item_id', 'ASC');
+    $select->orderBy('sai.item_id', $order);
 
     return $select;
   }
