Comment 2 for bug 715034

Revision history for this message
Timour Katchaounov (timour) wrote :

Analysis:

The failed assert is a result of calling Item_sum_distinct::clear() on an
incomplete object for which Item_sum_distinct::setup() was not yet
called.

The reason is that JOIN::exec for the outer query calls JOIN::reinit()
for all its subqueries, which in turn calls clear() for all aggregate functions
of the subqueries. The call stack is:
JOIN::reinit
mysql_select
mysql_explain_union
select_describe
JOIN::exec
mysql_select
mysql_explain_union

This assert doesn't fail in the main 5.3 because constant subqueries
are being executed during the optimize phase of the outer query,
thus the Unique object is created before calling JOIN::exec for the
outer query, and Item_sum_distinct::clear() actually cleans the
Unique object.

Solution:
The best solution is the obvious one - aubstitute the assert with
a test whether Item_sum_distinct::tree is NULL.