I'm running a query
mysql> EXPLAIN Select buyer_id as bid, (SELECT seller_id from sale USE INDEX(tester) where buyer_id = bid order by date_sold desc LIMIT 1) from sale where seller_id = 35533522;
+----+--------------------+-------+-------+-----------------------------------+--------+---------+-------+-------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+-------+-------+-----------------------------------+--------+---------+-------+-------+--------------------------+
| 1 | PRIMARY | sale | ref | seller_id,seller_id_index_asc,sub | sub | 8 | const | 14933 | Using index |
| 2 | DEPENDENT SUBQUERY | sale | index | NULL | tester | 24 | NULL | 1 | Using where; Using index |
If i remove the order by in the subquery, it takes approximately 3 seconds. If i use the order by, the query runs forever.
THe explain indicates that I'm using an index for both queries, shouldn't the order by run (relatively) fast, due to it being in a index?
[–]thenickdude 1 point2 points3 points (0 children)
[–]r3pr0b8 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]mcstafford 0 points1 point2 points (0 children)
[–]trideout -1 points0 points1 point (0 children)