aboutsummaryrefslogtreecommitdiff
path: root/app/Models/EntryDAO.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-07-10 15:49:51 +0200
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2014-07-10 15:49:51 +0200
commit6c83264f83221dcaa41d58e0b35b9925cde130e4 (patch)
treed0ffc006e5b32166f7c8ce63a65558ce2e62a10a /app/Models/EntryDAO.php
parentab9d656135e5afcafb824e73a49ff2e9fd2a2dbd (diff)
SQL: MySQL speed optimisation
Would be nice to test with other versions of MySQL too. Comparison before/after: mysql> EXPLAIN SELECT e.id, e.guid, e.title, e.author, UNCOMPRESS(content_bin) AS content, e.link, e.date, e.is_read, e.is_favorite, e.id_feed, e.tags FROM `freshrss_alex_entry` e INNER JOIN (SELECT e1.id FROM `freshrss_alex_entry` e1 INNER JOIN `freshrss_alex_feed` f ON e1.id_feed=f.id WHERE f.priority > 0 AND (e1.id >= 1381615200000000 OR e1.is_read=0 OR e1.is_favorite=1 OR (f.keep_history <> 0)) ORDER BY e1.id DESC LIMIT 31) e2 ON e2.id=e.id ORDER BY e.id DESC; +----+-------------+------------+--------+-------------------------------------+----------+---------+---------------+------+----------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+------------+--------+-------------------------------------+----------+---------+---------------+------+----------------------------------------------+ | 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 31 | Using temporary; Using filesort | | 1 | PRIMARY | e | eq_ref | PRIMARY | PRIMARY | 8 | e2.id | 1 | | | 2 | DERIVED | f | range | PRIMARY,priority,keep_history | priority | 1 | NULL | 137 | Using where; Using temporary; Using filesort | | 2 | DERIVED | e1 | ref | PRIMARY,id_feed,is_favorite,is_read | id_feed | 2 | freshrss.f.id | 452 | Using where | +----+-------------+------------+--------+-------------------------------------+----------+---------+---------------+------+----------------------------------------------+ 4 rows in set (3.50 sec) mysql> EXPLAIN SELECT e.id, e.guid, e.title, e.author, UNCOMPRESS(content_bin) AS content, e.link, e.date, e.is_read, e.is_favorite, e.id_feed, e.tags FROM `freshrss_alex_entry` e INNER JOIN (SELECT e1.id FROM `freshrss_alex_entry` e1 INNER JOIN `freshrss_alex_feed` f ON e1.id_feed=f.id WHERE f.priority > 0 AND e1.id <=9000000000000000 AND (e1.id >= 1381615200000000 OR e1.is_read=0 OR e1.is_favorite=1 OR (f.keep_history <> 0)) ORDER BY e1.id DESC LIMIT 31) e2 ON e2.id=e.id ORDER BY e.id DESC; +----+-------------+------------+--------+-------------------------------------+---------+---------+---------------------+-------+---------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+------------+--------+-------------------------------------+---------+---------+---------------------+-------+---------------------------------+ | 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 31 | Using temporary; Using filesort | | 1 | PRIMARY | e | eq_ref | PRIMARY | PRIMARY | 8 | e2.id | 1 | | | 2 | DERIVED | e1 | range | PRIMARY,id_feed,is_favorite,is_read | PRIMARY | 8 | NULL | 70084 | Using where | | 2 | DERIVED | f | eq_ref | PRIMARY,priority,keep_history | PRIMARY | 2 | freshrss.e1.id_feed | 1 | Using where | +----+-------------+------------+--------+-------------------------------------+---------+---------+---------------------+-------+---------------------------------+ 4 rows in set (0.01 sec)
Diffstat (limited to 'app/Models/EntryDAO.php')
-rw-r--r--app/Models/EntryDAO.php3
1 files changed, 3 insertions, 0 deletions
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index f184ab1fa..301a2ec49 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -352,6 +352,9 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
default:
throw new FreshRSS_EntriesGetter_Exception('Bad order in Entry->listByType: [' . $order . ']!');
}
+ if ($firstId === '' && parent::$sharedDbType === 'mysql') {
+ $firstId = '9000000000' . '000000'; //MySQL optimization. Tested on MySQL 5.5 with 150k articles
+ }
if ($firstId !== '') {
$where .= 'AND e1.id ' . ($order === 'DESC' ? '<=' : '>=') . $firstId . ' ';
}