• unknown's avatar
    Fix LP bug lp:802979 · 59784abe
    unknown authored
    Analysis:
    This bug consists of two related problems that are
    result of too early evaluation of single-row subqueries
    during the optimization phase of the outer query.
    
    Several optimizer code paths try to evaluate single-row
    subqueries in order to produce a constant and use that
    constant for further optimzation.
    
    When the execution of the subquery peforms destructive
    changes to the representation of the subquery, and these
    changes are not anticipated by the subsequent optimization
    phases of the outer query, we tipically get a crash or
    failed assert.
    
    Specifically, in this bug the inner-most suqbuery with
    DISTINCT triggers a substitution of the original JOIN
    object by a single-table JOIN object with a temp table
    needed to perform the DISTINCT operation (created by
    JOIN::make_simple_join).
    
    This substitution breaks EXPLAIN because:
    a) in the first example JOIN::cleanup no longer can
    reach the original table of the innermost subquery, and
    close all indexes, and
    b) in this second test query, EXPLAIN attempts to print
    the name of the internal temp table, and crashes because
    the temp table has no name (NULL pointer instead).
    
    Solution:
    a) fully disable subquery evaluation during optimization
    in all cases - both for constant propagation and range
    optimization, and
    b) change JOIN::join_free() to perform cleanup irrespective
    of EXPLAIN or not.
    59784abe
sp.result 167 KB