diff options
| author | 2025-11-15 23:17:13 +0100 | |
|---|---|---|
| committer | 2025-11-15 23:17:13 +0100 | |
| commit | b6314bee316488664360b77a2fb735853db507a5 (patch) | |
| tree | 85673d51b6d7ec72fccda411d4595f969600e69f | |
| parent | 39725cdde901011f6014dc0f4dff590ab427da0d (diff) | |
force correct index for MySQL when listing entries (#8211)
* force correct index for MySQL when listing entries
* Make special case for MySQL / MariaDB
---------
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
| -rw-r--r-- | app/Models/EntryDAO.php | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index d456b7711..0acc2c510 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -1443,11 +1443,14 @@ SQL; [$searchValues, $search] = $this->sqlListEntriesWhere(alias: 'e.', state: $state, filters: $filters, id_min: $id_min, id_max: $id_max, sort: $sort, order: $order, continuation_id: $continuation_id, continuation_values: $continuation_values); + // Help MySQL/MariaDB's optimizer with the query plan: + $useEntryIndex = $this->pdo->dbType() === 'mysql' ? 'USE INDEX (entry_feed_read_index) ' : ''; + return [array_merge($values, $searchValues), 'SELECT ' . ($type === 'T' ? 'DISTINCT ' : '') . 'e.id' . ($type === 'T' && $sort !== 'id' ? ', ' . $orderBy : '') // SELECT DISTINCT, ORDER BY expressions must appear in SELECT - . ' FROM `_entry` e ' + . ' FROM `_entry` e ' . $useEntryIndex . 'INNER JOIN `_feed` f ON f.id = e.id_feed ' . ($sort === 'c.name' ? 'INNER JOIN `_category` c ON c.id = f.category ' : '') . ($type === 't' || $type === 'T' ? 'INNER JOIN `_entrytag` et ON et.id_entry = e.id ' : '') |
