Skip to content

fix(db): add time_sensitive to jobs index for better query performance#58191

Open
QDenka wants to merge 1 commit intonextcloud:masterfrom
QDenka:fix/job-index-add-time-sensitive
Open

fix(db): add time_sensitive to jobs index for better query performance#58191
QDenka wants to merge 1 commit intonextcloud:masterfrom
QDenka:fix/job-index-add-time-sensitive

Conversation

@QDenka
Copy link

@QDenka QDenka commented Feb 8, 2026

Summary

Replaces the job_lastcheck_reserved index on the jobs table with a new job_sensitive_lastcheck_reserved index that includes the time_sensitive column.

Problem

The query for fetching background jobs filters on reserved_at, last_checked, and time_sensitive, but the existing index only covers last_checked and reserved_at. This forces the database to scan unnecessary rows when a maintenance window is configured.

Solution

Replace the index with (time_sensitive, last_checked, reserved_at) — putting the equality column first for optimal index usage, as recommended in the issue discussion.

As shown in the issue's ANALYZE output, this reduces scanned rows significantly (from 15 to 1 on the reporter's dev instance).

Fixes #46126

Signed-off-by: QDenka a@bigf.at

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 nextcloud#46126

Signed-off-by: QDenka <a@bigf.at>
@QDenka QDenka requested a review from a team as a code owner February 8, 2026 11:07
@QDenka QDenka requested review from ArtificialOwl, icewind1991, leftybournes and provokateurin and removed request for a team February 8, 2026 11:07
@solracsf solracsf added this to the Nextcloud 34 milestone Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Missing column in database index on query for time sensitive background jobs

2 participants