Pārlūkot izejas kodu

MariaDB restrict USE INDEX (#8460)

fix https://github.com/FreshRSS/FreshRSS/issues/8455
Follow-up of https://github.com/FreshRSS/FreshRSS/pull/8211
Alexandre Alapetite 2 mēneši atpakaļ
vecāks
revīzija
3097abfab6
1 mainītis faili ar 4 papildinājumiem un 1 dzēšanām
  1. 4 1
      app/Models/EntryDAO.php

+ 4 - 1
app/Models/EntryDAO.php

@@ -1454,7 +1454,10 @@ SQL;
 			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) ' : '';
+		$useEntryIndex = ($this->pdo->dbType() === 'mysql' &&	// Only relevant for MySQL/MariaDB,
+				in_array($type, ['a', 'A', 'Z', 'i', 's', 'f'], true) &&	// for some of the queries using the feed table,
+				preg_match('/is_read\\s*=\\s*[01]\\b/', $search))	// where is_read is a criteria
+			? 'USE INDEX (entry_feed_read_index) ' : '';
 
 		return [array_merge($values, $searchValues), 'SELECT '
 			. ($type === 'T' ? 'DISTINCT ' : '')