Comment 1 for bug 868908

Revision history for this message
Sergey Petrunia (sergefp) wrote :

The crash is caused by the following execution scenario:

PREPARE command:
> parent subquery calls convert_join_subqueries_to_semi_joins()
   - it switches to statement' Arena. (AA)
   - subquery is converted into a non-mergeable semi-join nest,
  > convert_subq_to_jtbm()
     > it calls child_join->optimize()
       (this is necessary because of how JOIN::choose_subquery_plan() works.
        in particular, it may figure out that Materialization is not applicable after all
        and this information needs to be returned to convert_subq_to_jtbm() so that
        it aborts the conversion)
        > child_join->optimize() works:
           - switches to statement arena *AGAIN* (BB)
           - it calls simplify_joins(), which converts the outer join into inner.
           - while doing the above, it creates an Item_cond_and() object. The object is added into
              thd->free_list.

From this point, the execution proceeds normally, except that double activation (at (AA) and (BB) ) and de-activation of statement mem_root leaves the Item_cond_and un-recorded in Statement's free_list.
As a consequence of this, Item_cond_and->cleanup() is never called, and on next execution we get situation
where

Item_cond_and->fixed=TRUE
Item_cond_and->list->nth_element(0)->fixed= FALSE
Item_cond_and->list->nth_element(1)->fixed= FALSE

this causes us to assert when accessing one of Item_cond_and's chlldren.