diff --git a/core/Listener/AddMissingIndicesListener.php b/core/Listener/AddMissingIndicesListener.php index 27880fabeac9a..d84399993952f 100644 --- a/core/Listener/AddMissingIndicesListener.php +++ b/core/Listener/AddMissingIndicesListener.php @@ -152,8 +152,8 @@ public function handle(Event $event): void { $event->addMissingIndex( 'jobs', - 'job_lastcheck_reserved', - ['last_checked', 'reserved_at'] + 'job_lastcheck_timesens', + ['last_checked', 'reserved_at', 'time_sensitive'], ); $event->addMissingIndex( diff --git a/core/Migrations/Version33000Date20260224000000.php b/core/Migrations/Version33000Date20260224000000.php new file mode 100644 index 0000000000000..30a8f1d1796e7 --- /dev/null +++ b/core/Migrations/Version33000Date20260224000000.php @@ -0,0 +1,57 @@ +hasTable('jobs')) { + return null; + } + + $table = $schema->getTable('jobs'); + + // Drop the old index that only covers last_checked and reserved_at + if ($table->hasIndex('job_lastcheck_reserved')) { + $table->dropIndex('job_lastcheck_reserved'); + } + + // Recreate the index with time_sensitive included. + // This allows the background job scheduler query to use a full index scan + // instead of a partial index + row lookup, improving performance when + // a maintenance window restricts which jobs are eligible to run. + if (!$table->hasIndex('job_lastcheck_timesens')) { + $table->addIndex( + ['last_checked', 'reserved_at', 'time_sensitive'], + 'job_lastcheck_timesens', + ); + } + + return $schema; + } +}