Bug #1232 | Optimizer chooses wrong plan on simple join | ||
---|---|---|---|
Submitted: | 9 Sep 2003 3:35 | Modified: | 13 Dec 2003 13:51 |
Reporter: | Jeremy Cole (Basic Quality Contributor) (OCA) | Email Updates: | |
Status: | Can't repeat | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 4.1.1 (20030830) | OS: | |
Assigned to: | Igor Babaev | CPU Architecture: | Any |
[9 Sep 2003 3:35]
Jeremy Cole
[17 Sep 2003 0:29]
Jeremy Cole
You can download a mysqldump of the 'mail' database at: http://jcole.us/files/mail.sql.gz
[13 Dec 2003 13:51]
Igor Babaev
With the latest version of 4.1 (as of 2003.12.13) I could not reproduce it with the database Jeremy provided me with. I had to modify the type descriptors of columns address and comment of the address table to COLLATE latin1_general_cs NOT NULL to make the fulltext index idx_ft_all(phrase, address, comment) valid. After this I had: mysql> explain -> select sql_no_cache mail.mail_id, mail.folder_id -> from mail left join mxa on mail.mail_id=mxa.mail_id and mxa.type='from' -> left join address on mxa.address_id=address.address_id -> order by mail.h_date desc -> limit 5; +----+-------------+---------+--------+---------------+---------+---------+-------------------------+-------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+---------+--------+---------------+---------+---------+-------------------------+-------+-------------+ | 1 | SIMPLE | mail | index | NULL | h_date | 8 | NULL | 30800 | | | 1 | SIMPLE | mxa | ref | mail_id,type | mail_id | 6 | mail.mail.mail_id,const | 1 | | | 1 | SIMPLE | address | eq_ref | PRIMARY | PRIMARY | 4 | mail.mxa.address_id | 1 | Using index | +----+-------------+---------+--------+---------------+---------+---------+-------------------------+-------+-------------+ 3 rows in set (0.00 sec) mysql> explain -> select sql_no_cache mail.mail_id, folder.f_name -> from mail left join folder on mail.folder_id=folder.folder_id -> left join mxa on mail.mail_id=mxa.mail_id and mxa.type='from' -> left join address on mxa.address_id=address.address_id -> order by mail.h_date desc -> limit 5; +----+-------------+---------+--------+---------------+---------+---------+-------------------------+-------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+---------+--------+---------------+---------+---------+-------------------------+-------+-------------+ | 1 | SIMPLE | mail | index | NULL | h_date | 8 | NULL | 30800 | | | 1 | SIMPLE | folder | eq_ref | PRIMARY | PRIMARY | 4 | mail.mail.folder_id | 1 | | | 1 | SIMPLE | mxa | ref | mail_id,type | mail_id | 6 | mail.mail.mail_id,const | 1 | | | 1 | SIMPLE | address | eq_ref | PRIMARY | PRIMARY | 4 | mail.mxa.address_id | 1 | Using index | +----+-------------+---------+--------+---------------+---------+---------+-------------------------+-------+-------------+ 4 rows in set (0.00 sec) mysql> select sql_no_cache mail.mail_id, mail.folder_id -> from mail left join mxa on mail.mail_id=mxa.mail_id and mxa.type='from' -> left join address on mxa.address_id=address.address_id -> order by mail.h_date desc -> limit 5; +---------+-----------+ | mail_id | folder_id | +---------+-----------+ | 739 | 1 | | 738 | 1 | | 737 | 1 | | 736 | 1 | | 735 | 1 | +---------+-----------+ 5 rows in set (0.00 sec) mysql> select sql_no_cache mail.mail_id, folder.f_name -> from mail left join folder on mail.folder_id=folder.folder_id -> left join mxa on mail.mail_id=mxa.mail_id and mxa.type='from' -> left join address on mxa.address_id=address.address_id -> order by mail.h_date desc -> limit 5; +---------+--------+ | mail_id | f_name | +---------+--------+ | 739 | cllug | | 738 | cllug | | 737 | cllug | | 736 | cllug | | 735 | cllug | +---------+--------+ 5 rows in set (0.01 sec)