fix(db): add time_sensitive to jobs index for better query performance#58191
Open
QDenka wants to merge 1 commit intonextcloud:masterfrom
Open
fix(db): add time_sensitive to jobs index for better query performance#58191QDenka wants to merge 1 commit intonextcloud:masterfrom
QDenka wants to merge 1 commit intonextcloud:masterfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the
job_lastcheck_reservedindex on thejobstable with a newjob_sensitive_lastcheck_reservedindex that includes thetime_sensitivecolumn.Problem
The query for fetching background jobs filters on
reserved_at,last_checked, andtime_sensitive, but the existing index only coverslast_checkedandreserved_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