• unknown's avatar
    Fix for a BUG#31898: 16M memory allocations for user variables · 819eaead
    unknown authored
    in stored procedure.
    
    The problem was that MySQL used unnecessarily large amounts of
    memory if user variables were used as an argument to CONCAT or
    CONCAT_WS -- 16M per each user variable used.
    
    Technically, it happened because MySQL used the following
    allocation strategy for string functions to avoid multiple
    realloc() calls: in the virtual operation fix_length_and_dec()
    the attribute max_length was calculated as a sum of max_length
    values for each argument.
    
    Although this approach worked well for small (or fixed) data types,
    there could be a problem if there as a user variable among
    the arguments of a string function -- max_length of the function
    would be 16M (as the max_length of a user variable is 16M).
    
    Both CONCAT() and CONCAT_WS() functions suffer from this problem.
    
    The fix is to do not use meta-data for allocating memory.
    The following strategy is proposed instead: allocate the exact
    length of the result string at the first record, double the amount
    of memory allocated when it is required.
    
    No test case for this bug because there is no way to test memory
    consumption in a robust way with our test suite.
    
    
    sql/item_strfunc.cc:
      Implement memory-wise allocation strategy.
    819eaead
item_strfunc.cc 87.7 KB