From d133de6684ff92bf25c3362b58e2f6ee337beb80 Mon Sep 17 00:00:00 2001
From: Marius Bobin <mbobin@gitlab.com>
Date: Wed, 25 Aug 2021 14:35:53 +0300
Subject: [PATCH] Add comment to explain why we're sorting the rows

---
 app/workers/stuck_ci_jobs_worker.rb | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/app/workers/stuck_ci_jobs_worker.rb b/app/workers/stuck_ci_jobs_worker.rb
index 04bef83040f7a..7754f0d2d27e0 100644
--- a/app/workers/stuck_ci_jobs_worker.rb
+++ b/app/workers/stuck_ci_jobs_worker.rb
@@ -43,6 +43,9 @@ def perform
   private
 
   # rubocop: disable CodeReuse/ActiveRecord
+  # We're adding the ordering clause by `created_at` and `project_id`
+  # because we want to force the query planner to use the
+  # `ci_builds_gitlab_monitor_metrics` index all the time.
   def pending_builds(timeout)
     if Feature.enabled?(:ci_new_query_for_pending_stuck_jobs)
       Ci::Build.pending.created_at_before(timeout).updated_at_before(timeout).order(created_at: :asc, project_id: :asc)
-- 
GitLab