MySQL Forums
Forum List  »  Optimizer & Parser

Unexpected join optimization
Posted by: Grace Zhu
Date: April 17, 2009 01:21PM

We have a custom storage engine to process the query execution but rely on MySQL optimizer to give us the execution plan. We give the same records info for all the tables and hope MySQL optimizer would treat all tables even.

It worked most of time. But it looks like when the join column sizes are different, the optimizer does not look at the from clause table order any more. Instead, it looks at the left and right side of the join filter.

Given l_orderkey is 8bytes column and p_partkey is 4bytes column, this following query gives us the desired behavior, which lineitem is treated as small side:

Select l_quantity, max(p_retailprice) from lineitem, part where l_orderkey < 1000000 and p_partkey=l_orderkey group by l_quantity order by l_quantity;

By just flipping the join order, part is decided to be small side now (open first), which is not ideal:

Select l_quantity, max(p_retailprice) from part,lineitem where l_orderkey < 1000000 and l_orderkey=p_partkey group by l_quantity order by l_quantity;

Adding straight_join hint does not make any difference to either case.

Does anyone has an explanation for this optimizer behavior? Even better if there's anything we can do to avoid this.

Thanks in advance.

Grace

Options: ReplyQuote


Subject
Views
Written By
Posted
Unexpected join optimization
3628
April 17, 2009 01:21PM
2281
April 17, 2009 02:36PM


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.