Problem/Motivation
We've recently run into some performance issues for a very queue heavy site. Upon investigation we identified additional load exerted on the site as a result of garbage collection for the queue table, which uses this query:
$this->connection->delete(static::TABLE_NAME)
->condition('created', \Drupal::time()->getRequestTime() - 864000, '<')
->condition('name', 'drupal_batch:%', 'LIKE')
->execute();
The issue here is that a composite index exists on the queue table, with the order 'name', 'created'. This inverting of the two fields means the index cannot be fully utilised. Switching them in the query vastly improves performance for the delete.
Steps to reproduce
- Add a number of failed batches to the queue table - haven't worked on the exact conditions that can cause this outside of our specific use case.
- Run garbage collection
- Identify slow SQL queries
Proposed resolution
Swap order of query to match order of index.
Remaining tasks
TBC
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A