• Igor Babaev's avatar
    MDEV-15035 Wrong results when calling a stored procedure · eb057dce
    Igor Babaev authored
    multiple times with different arguments.
    
    If the ON expression of an outer join is an OR formula with one
    of the disjunct being a constant formula then the expression
    cannot be null-rejected if the constant formula is true. Otherwise
    it can be null-rejected and if so the outer join can be converted
    into inner join. This optimization was added in the patch for
    mdev-4817. Yet the code had a defect: if the query was used in
    a stored procedure with parameters and the constant item contained
    some of them then the value of this constant item depended on the
    values of the parameters. With some parameters it may be true,
    for others not. The validity of conversion to inner join is checked
    only once and it happens only for the first call of procedure.
    So if the  parameters in the first call allowed the conversion it
    was done and next calls used the transformed query though there
    could be calls whose parameters made the conversion invalid.
    
    Fixed by cheking whether the constant disjunct in the ON expression
    originally contained an SP parameter. If so the expression is not
    considered as null-rejected. For this check a new item's attribute
    was intruduced: Item::with_param. It is calculated for each item
    by fix fields() functions.
    Also moved the call of optimize_constant_subqueries() in
    JOIN::optimize after the call of simplify_joins(). The reason
    for this is that after the optimization introduced by the patch
    for mdev-4817 simplify_joins() can use the results of execution
    of non-expensive constant subqueries and this is not valid.
    eb057dce
item_func.cc 183 KB