• unknown's avatar
    Fix for BUG#14920 Ordering aggregated result sets corrupts resultset. · e3f57552
    unknown authored
    The cause of the bug was the use of end_write_group instead of end_write
    in the case when ORDER BY required a temporary table, which didn't take
    into account the fact that loose index scan already computes the result
    of MIN/MAX aggregate functions (and performs grouping).
    
    The solution is to call end_write instead of end_write_group and to add
    the MIN/MAX functions to the list of regular functions so that their
    values are inserted into the temporary table.
    
    
    mysql-test/r/group_min_max.result:
      Test for BUG#14920
    mysql-test/t/group_min_max.test:
      Test for BUG#14920
    sql/sql_class.cc:
      Added new member to TMP_TABLE_PARAM.
    sql/sql_class.h:
      Added new member to TMP_TABLE_PARAM.
    sql/sql_select.cc:
      Enable result rows generated by loose index scan being written into
      a temporary table. The change is necessary because loose index
      scan already computes the result of GROUP BY and the MIN/MAX aggregate
      functions. This is realized by three changes:
      - create_tmp_table allocates space for aggregate functions in the
        list of regular functions,
      - use end_write instead of end_write group,
      - copy the pointers to the MIN/MAX aggregate functions to the list
        of regular functions TMP_TABLE_PARAM::items_to_copy.
    sql/sql_select.h:
      New parameter to create_tmp_table.
    e3f57552
sql_select.h 17.7 KB