• evgen@moonbone.local's avatar
    Fixed bug#15560: GROUP_CONCAT wasn't ready for WITH ROLLUP queries · 1c13e548
    evgen@moonbone.local authored
    The GROUP_CONCAT uses its own temporary table. When ROLLUP is present
    it creates the second copy of Item_func_group_concat. This copy receives the
    same list of arguments that original group_concat does. When the copy is
    set up the result_fields of functions from the argument list are reset to the
    temporary table of this copy.
    As a result of this action data from functions flow directly to the ROLLUP copy
    and the original group_concat functions shows wrong result.
    Since queries with COUNT(DISTINCT ...) use temporary tables to store
    the results the COUNT function they are also affected by this bug.
    
    The idea of the fix is to copy content of the result_field for the function
    under GROUP_CONCAT/COUNT from  the first temporary table to the second one,
    rather than setting result_field to point to the second temporary table.
    To achieve this goal force_copy_fields flag is added to Item_func_group_concat
    and Item_sum_count_distinct classes. This flag is initialized to 0 and set to 1
    into the make_unique() member function of both classes.
    To the TMP_TABLE_PARAM structure is modified to include the similar flag as
    well.
    The create_tmp_table() function passes that flag to create_tmp_field().
    When the flag is set the create_tmp_field() function will set result_field
    as a source field and will not reset that result field to newly created 
    field for Item_func_result_field and its descendants. Due to this there
    will be created copy func to copy data from old result_field to newly 
    created field.
    1c13e548
sql_table.cc 110 KB