Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mysql> explain SELECT SQL_NO_CACHE *
- -> FROM
- -> blog
- -> join
- -> (
- -> SELECT max(dateline) maxdateline
- -> , blog.userid userid
- -> FROM
- -> blog
- -> GROUP BY
- -> blog.userid
- -> ORDER BY
- -> max(dateline) DESC
- -> LIMIT
- -> 250
- -> ) grouper
- -> on ( blog.dateline = grouper.maxdateline and blog.userid = grouper.userid);
- +----+-------------+------------+-------+-----------------+----------+---------+------------------------------------+------+----------------------------------------------+
- | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
- +----+-------------+------------+-------+-----------------+----------+---------+------------------------------------+------+----------------------------------------------+
- | 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 250 | |
- | 1 | PRIMARY | blog | ref | dateline,userid | dateline | 8 | grouper.maxdateline,grouper.userid | 1 | |
- | 2 | DERIVED | blog | index | NULL | userid | 9 | NULL | 1054 | Using index; Using temporary; Using filesort |
- +----+-------------+------------+-------+-----------------+----------+---------+------------------------------------+------+----------------------------------------------+
- 3 rows in set (0.00 sec)
- mysql> explain select t1.* from blog t1
- -> where t1.dateline= (
- -> SELECT max(t2.dateline) from blog t2 where t2.userid=t1.userid
- -> )
- -> order by t1.dateline desc
- -> limit 250;
- +----+--------------------+-------+-------+---------------+----------+---------+-------------------+-------+-------------+
- | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
- +----+--------------------+-------+-------+---------------+----------+---------+-------------------+-------+-------------+
- | 1 | PRIMARY | t1 | index | NULL | dateline | 9 | NULL | 15804 | Using where |
- | 2 | DEPENDENT SUBQUERY | t2 | ref | userid | userid | 4 | uantona.t1.userid | 15 | Using index |
- +----+--------------------+-------+-------+---------------+----------+---------+-------------------+-------+-------------+
- 2 rows in set (0.00 sec)
Add Comment
Please, Sign In to add comment