eab6d1c954
Sorting on notice.id when our primary selector was notice_inbox.user_id caused a filesort and table scan of the notice table. Switchng to notice_inbox's notice_id means we can use our index, and everything comes right up. Before: mysql> explain SELECT notice.id AS id FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id WHERE notice_inbox.user_id = 18574 AND notice.repeat_of IS NULL ORDER BY notice.id DESC LIMIT 61 OFFSET 0; +----+-------------+--------------+--------+------------------------------------+---------+---------+-------------------------------+--------+----------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------------+--------+------------------------------------+---------+---------+-------------------------------+--------+----------------------------------------------+ | 1 | SIMPLE | notice_inbox | ref | PRIMARY,notice_inbox_notice_id_idx | PRIMARY | 4 | const | 102600 | Using index; Using temporary; Using filesort | | 1 | SIMPLE | notice | eq_ref | PRIMARY | PRIMARY | 4 | stoica.notice_inbox.notice_id | 1 | Using index | +----+-------------+--------------+--------+------------------------------------+---------+---------+-------------------------------+--------+----------------------------------------------+ After: mysql> explain SELECT notice.id AS id FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id WHERE notice_inbox.user_id = 18574 AND notice.repeat_of IS NULL ORDER BY notice_id DESC LIMIT 61 OFFSET 0; +----+-------------+--------------+--------+------------------------------------+---------+---------+-------------------------------+--------+--------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------------+--------+------------------------------------+---------+---------+-------------------------------+--------+--------------------------+ | 1 | SIMPLE | notice_inbox | ref | PRIMARY,notice_inbox_notice_id_idx | PRIMARY | 4 | const | 102816 | Using where; Using index | | 1 | SIMPLE | notice | eq_ref | PRIMARY,notice_repeatof_idx | PRIMARY | 4 | stoica.notice_inbox.notice_id | 1 | Using where | +----+-------------+--------------+--------+------------------------------------+---------+---------+-------------------------------+--------+--------------------------+ |
||
---|---|---|
.. | ||
Avatar.php | ||
Config.php | ||
Confirm_address.php | ||
Consumer.php | ||
Deleted_notice.php | ||
Design.php | ||
Fave.php | ||
File_oembed.php | ||
File_redirection.php | ||
File_thumbnail.php | ||
File_to_post.php | ||
File.php | ||
Foreign_link.php | ||
Foreign_service.php | ||
Foreign_subscription.php | ||
Foreign_user.php | ||
Group_alias.php | ||
Group_block.php | ||
Group_inbox.php | ||
Group_member.php | ||
Invitation.php | ||
Location_namespace.php | ||
Login_token.php | ||
Memcached_DataObject.php | ||
Message.php | ||
Nonce.php | ||
Notice_inbox.php | ||
Notice_source.php | ||
Notice_tag.php | ||
Notice.php | ||
Profile_block.php | ||
Profile_role.php | ||
Profile_tag.php | ||
Profile.php | ||
Queue_item.php | ||
Related_group.php | ||
Remember_me.php | ||
Remote_profile.php | ||
Reply.php | ||
Session.php | ||
Sms_carrier.php | ||
status_network.ini | ||
Status_network.php | ||
statusnet.ini | ||
statusnet.links.ini | ||
Subscription.php | ||
Token.php | ||
User_group.php | ||
User.php |