MySQL Forums
Forum List  »  Optimizer & Parser

Can't understand why optimizer doesn't work properly :(
Posted by: Sergey Belov
Date: July 23, 2007 02:03PM

There is a query:

SELECT *
FROM Messages WHERE EXISTS (
SELECT 1
FROM Ask
WHERE Ask.Ask = Messages.Ask
AND Ask.DateTime < 20070710
)
LIMIT 1 , 30

Optimizer scans all `Messages` table. But all tables are indexed by necessary fields. An EXPLAIN output here:

mysql> EXPLAIN SELECT *
-> FROM Messages
-> WHERE EXISTS (
-> SELECT 1
-> FROM Ask
-> WHERE Ask.Ask = Messages.Ask
-> AND Ask.DateTime < 20070710
-> )
-> LIMIT 1 , 30;
+----+--------------------+----------+------+-----------------------------+---------+---------+--------------------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+----------+------+-----------------------------+---------+---------+--------------------+--------+-------------+
| 1 | PRIMARY | Messages | ALL | NULL | NULL | NULL | NULL | 233869 | Using where |
| 2 | DEPENDENT SUBQUERY | Ask | ref | PRIMARY,DateTime,DateTime_2 | PRIMARY | 3 | forum.Messages.Ask | 2 | Using where |
+----+--------------------+----------+------+-----------------------------+---------+---------+--------------------+--------+-------------+
2 rows in set (0.00 sec)

Options: ReplyQuote




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.