Re: Query with GROUP BY (Using index for group-by -> Using index)
Posted by:
mnf
Date: December 01, 2006 12:21AM
mysql> EXPLAIN SELECT i, n, t, v FROM shn1 AS outer WHERE i = (SELECT MAX(i) FROM shn1 WHERE n=outer.n);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'outer WHERE i = (SELECT MAX(i) FROM shn1 WHERE n=outer.n)' at line 1
If you mean this:
mysql> EXPLAIN SELECT i, n, t, v FROM shn1 AS T1 WHERE i = (SELECT MAX(i) FROM shn1 WHERE n = T1.n);
+----+--------------------+-------+------+---------------+------+---------+---------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+-------+------+---------------+------+---------+---------+---------+-------------+
| 1 | PRIMARY | T1 | ALL | NULL | NULL | NULL | NULL | 7699429 | Using where |
| 2 | DEPENDENT SUBQUERY | shn1 | ref | n,ni,nt | ni | 2 | br.T1.n | 35811 | Using index |
+----+--------------------+-------+------+---------------+------+---------+---------+---------+-------------+
then it is full scan again, takes hours, and obviously is not "SELECT MAX(i) FROM shn1 GROUP BY n".
Subject
Views
Written By
Posted
9600
November 30, 2006 05:20AM
3610
November 30, 2006 08:18PM
Re: Query with GROUP BY (Using index for group-by -> Using index)
3686
December 01, 2006 12:21AM
3362
December 06, 2006 02:03AM
3111
December 07, 2006 12:19AM
3243
December 25, 2006 06:35AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.