fix(db): add time_sensitive to jobs index for better query performance#58191
fix(db): add time_sensitive to jobs index for better query performance#58191QDenka 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>
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
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