• unknown's avatar
    Fixed bug#15560: GROUP_CONCAT wasn't ready for WITH ROLLUP queries · 8d5277a7
    unknown 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.
    
    
    mysql-test/t/func_gconcat.test:
      Added test for bug#15560: GROUP_CONCAT wasn't ready for WITH ROLLUP queries
    mysql-test/r/func_gconcat.result:
      Added test for bug#15560: GROUP_CONCAT wasn't ready for WITH ROLLUP queries
    sql/sql_table.cc:
      Fixed bug#15560: GROUP_CONCAT wasn't ready for WITH ROLLUP queries
      Added 0 as a last parameter to create_tmp_field()  to force old behaviour.
    sql/sql_select.cc:
      Fixed bug#15560: GROUP_CONCAT wasn't ready for WITH ROLLUP queries
      
      Added the flag 'make_copy_field' to create_tmp_field(), so that for Item_result_field descendants create_tmp_field() sets the item's result field as a source field and deny resetting that result field to a new value.
    sql/sql_class.h:
      Fixed bug#15560: GROUP_CONCAT wasn't ready for WITH ROLLUP queries
      Added the flag 'force_copy_fields' to the structure TMP_TABLE_PARAM in order to make create_tmp_field() force the creation of 'copy_field' objects.
    sql/mysql_priv.h:
      Fixed bug#15560: GROUP_CONCAT wasn't ready for WITH ROLLUP queries
      Added the bool parameter 'make_copy_field' to create_tmp_field().
    sql/item_sum.cc:
      Fixed bug#15560: GROUP_CONCAT wasn't ready for WITH ROLLUP queries
      Added initialization of the force_copy_fields flag and passing it to create_tmp_table() through TMP_TBLE_PARAM in the Item_func_group_concat and Item_sum_count_distinct member functions.
    sql/item_sum.h:
      Fixed bug#15560: GROUP_CONCAT wasn't ready for WITH ROLLUP queries
      Added the flag 'force_copy_fields' to the Item_func_group_concat and Item_sum_count_distinct classes.
    8d5277a7
item_sum.cc 45.9 KB