• unknown's avatar
    Fixed bug#16716: subselect in concat() may lead to a wrong result. · 1991a87d
    unknown authored
    The Item_func_concat::val_str() function tries to make as less re-allocations
    as possible. This results in appending strings returned by 2nd and next
    arguments to the string returned by 1st argument if the buffer for the first
    argument has enough free space. A constant subselect is evaluated only once 
    and its result is stored in an Item_cache_str. In the case when the first
    argument of the concat() function is such a subselect Item_cache_str returns
    the stored value and Item_func_concat::val_str() append values of other
    arguments to it. But for the next row the value in the Item_cache_str isn't
    restored because the subselect is a constant one and it isn't evaluated second
    time. This results in appending string values of 2nd and next arguments to the 
    result of the previous Item_func_concat::val_str() call.
    
    The Item_func_concat::val_str() function now checks whether the first argument 
    is a constant one and if so it doesn't append values of 2nd and next arguments
    to the string value returned by it.
    
    
    mysql-test/t/func_concat.test:
      Added test case for bug#16716: subselect in concat() may lead to a wrong result.
    mysql-test/r/func_concat.result:
      Added test case for bug#16716: subselect in concat() may lead to a wrong result.
    sql/item_strfunc.cc:
      Fixed bug#16716: subselect in concat() may lead to a wrong result.
      The Item_func_concat::val_str() function now checks whether the first argument 
      is a constant one and if so it doesn't append values of 2nd and next arguments
      to the string value returned by it.
    1991a87d
func_concat.result 1.91 KB