• konstantin@mysql.com's avatar
    A fix and test case for Bug#5987 "subselect in bool function · daa4c249
    konstantin@mysql.com authored
    crashes server (prepared statements)": the bug was that all boolean
    items always recovered its original arguments at statement cleanup 
    stage.
    This collided with Item_subselect::select_transformer, which tries to 
    permanently change the item tree to use a transformed subselect instead of
    original one.
    So we had this call sequence for prepare:
    mysql_stmt_prepare -> JOIN::prepare -> 
    Item_subselect::fix_fields -> the item tree gets transformed ->
    Item_bool_rowready_func2::cleanup, item tree is recovered to original
    state, while it shouldn't have been;
    mysql_stmt_execute -> attempts to execute a broken tree -> crash.
    Now instead of bluntly recovering all arguments of bool functions in 
    Item_bool_rowready_func2::cleanup, we recover only those
    which were changed, and do it in one place.
    There still would exist a possibility for a collision with subselect
    tranformation, if permanent and temporary changes were performed at the 
    same stage.
    But fortunately subselect transformation is always done first, so it 
    doesn't conflict with the optimization done by propogate_cond_constants.
    Now we have: 
    mysql_stmt_prepare -> JOIN::prepare -> subselect transformation 
    permanently changes the tree -> cleanup doesn't recover anything, 
    because nothing was registered for recovery.
    mysql_stmt_execute -> JOIN::prepare (the tree is already transformed, 
    so it doesn't change), JOIN::optimize -> 
    propogate_cond_constants -> temporary changes the item tree 
    with constants -> JOIN::execute -> cleanup -> 
    the changes done by propogate_cond_constants are recovered, as
    they were registered for recovery.
    daa4c249
item_cmpfunc.h 27.3 KB