From 698ea2460eba10f4953ab36b7e69c564e701c3d6 Mon Sep 17 00:00:00 2001 From: QDenka Date: Sun, 8 Feb 2026 11:07:05 +0000 Subject: [PATCH] fix(db): add time_sensitive to jobs index for better query performance The query for fetching time-sensitive background jobs filters on reserved_at, last_checked, and time_sensitive columns, but the existing index job_lastcheck_reserved only covers last_checked and reserved_at. This causes the database to scan unnecessary rows when the maintenance window is configured. Replace the index with a new one that includes time_sensitive as the first column (equality before range) for optimal index usage. Fixes #46126 Signed-off-by: QDenka --- core/Listener/AddMissingIndicesListener.php | 8 +++++--- core/Migrations/Version13000Date20170718121200.php | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/Listener/AddMissingIndicesListener.php b/core/Listener/AddMissingIndicesListener.php index 27880fabeac9a..4f3160a4bf15a 100644 --- a/core/Listener/AddMissingIndicesListener.php +++ b/core/Listener/AddMissingIndicesListener.php @@ -150,10 +150,12 @@ public function handle(Event $event): void { ); - $event->addMissingIndex( + $event->replaceIndex( 'jobs', - 'job_lastcheck_reserved', - ['last_checked', 'reserved_at'] + ['job_lastcheck_reserved'], + 'job_sensitive_lastcheck_reserved', + ['time_sensitive', 'last_checked', 'reserved_at'], + false, ); $event->addMissingIndex( diff --git a/core/Migrations/Version13000Date20170718121200.php b/core/Migrations/Version13000Date20170718121200.php index e3ac88a3e31af..b7f9bb695dea6 100644 --- a/core/Migrations/Version13000Date20170718121200.php +++ b/core/Migrations/Version13000Date20170718121200.php @@ -504,7 +504,7 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op ]); $table->setPrimaryKey(['id']); $table->addIndex(['class'], 'job_class_index'); - $table->addIndex(['last_checked', 'reserved_at'], 'job_lastcheck_reserved'); + $table->addIndex(['time_sensitive', 'last_checked', 'reserved_at'], 'job_sensitive_lastcheck_reserved'); } if (!$schema->hasTable('users')) {