MySQL Forums
Forum List  »  Optimizer & Parser

Re: why does explain plan change?
Posted by: Fabio Sgamo
Date: August 03, 2007 05:22AM

Just a quick answer to "So the optimizer is choosing these different plans seemingly at random, though I don't really think that would be the case. Why does something like this happen, and more importantly, how can I ensure the optimizer uses the more efficient plan in this case?"

The optimizer computes which it considers the best plan, every time a query is executed, and the plan is calculated on static and dinamic data (not randomly!). The numbers of records in every table involved, and the key distributions of the indexes used, are the dinamic data. As you noticed, running ANALYZE changed the plan (http://dev.mysql.com/doc/refman/5.0/en/analyze-table.html): after your tables got "scrambled" by insert/delete, the optimizer "wasn't in touch" with the actual data in tables, and ANALYZE did the right trick

Than, just learn how to use LEFT JOIN, making your select from one table only: the WHERE gets freed by joining condition, and it COULD be optimized even better.

Options: ReplyQuote


Subject
Views
Written By
Posted
11910
July 30, 2007 10:14AM
Re: why does explain plan change?
3258
August 03, 2007 05:22AM


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.