Bug #904 | query jumped from 4 seconds to several minutes, join order changed in explain | ||
---|---|---|---|
Submitted: | 23 Jul 2003 20:53 | Modified: | 7 Aug 2003 22:21 |
Reporter: | Shane Allen | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: MyISAM storage engine | Severity: | S1 (Critical) |
Version: | 4.0.14 | OS: | Linux (debian linux) |
Assigned to: | Igor Babaev | CPU Architecture: | Any |
[23 Jul 2003 20:53]
Shane Allen
[25 Jul 2003 7:52]
Indrek Siitan
Yes, it would be really helpful if you could provide the data. The bugs database doesn't support uploading files over 1MB in size, so you need to either make the files available on your WWW/FTP site and let us know of the location (mail to tfr@mysql.com) or upload them to our FTP at: http://support.mysql.com/pub/mysql/secret Thanks.
[28 Jul 2003 11:22]
Shane Allen
I will be sending an email to the address provided earlier with the location of the download. FYI, I have been unable to contact support.mysql.com via FTP for the weekend; it is refusing connections, and making an http request (as directed in the previous comment on this ticket) generates a 404.
[29 Jul 2003 4:34]
Indrek Siitan
Thanks for the data - I have been able to verify the behaviour.
[6 Aug 2003 18:12]
Shane Allen
Do you guys by any chance have a timeline for finding and/or fixing this bug? We're waiting on a production rollout, because we don't know how many other places on our site this bug could affect. If you don't yet have a timeline, please let me know, so that we can try to code around the bug (we need to get some of the 4.0.14 bugfixes rolled out). If you have any details at all with regards to what causes it, it would be helpful for us to know them should we need to identify other problem spots on our site. Thanks
[7 Aug 2003 22:21]
Igor Babaev
This is not a bug. Due to the latest changes in the optimizer an outer join can be converted to an inner join. It happens when the where condition effectively filters out NULL rows of the inner table. The regular search for the best execution plan is applied to the result of conversion. The optimizer choice is based on the statistics it can collect. Unfortunately it can not use statistics on non-indexed column, because it's not collected now. That's why even when we have a condition with a good selectivity (a restrictive condition) the optimizer doesn't take it into account at all. So, if the condition imposes restrictions for the columns of an inner table of the execution plan it is checked only when rows for outer tables are already fetched and in most cases uselessly. To resolve this problem it's recommended to create indexes for columns used in restrictive conditions. When I created an index for the column t_time in the table user_account I immediately got a good execution plan for the query: +-------+--------+---------------------------+------------+---------+---------+------+----------------------------------------------+ | table | type | possible_keys | key | key_len | ref | rows | Extra | +-------+--------+---------------------------+------------+---------+---------+------+----------------------------------------------+ | ua | range | uid,t_time | t_time | 9 | NULL | 1112 | Using where; Using temporary; Using filesort | | rcd | eq_ref | PRIMARY | PRIMARY | 3 | ua.uid | 1 | Using where | | l | ref | PRIMARY,status,seller_uid | seller_uid | 4 | rcd.uid | 10 | Using where | | fs | eq_ref | PRIMARY | PRIMARY | 4 | rcd.uid | 1 | Using where; Using index; Not exists | +-------+--------+---------------------------+------------+---------+---------+------+----------------------------------------------+ 4 rows in set (0.00 sec) With this plan the execution took practically no time.