• Evgeny Potemkin's avatar
    Bug#50539: Wrong result when loose index scan is used for an aggregate · 2d18c5be
    Evgeny Potemkin authored
               function with distinct.
    Loose index scan is used to find MIN/MAX values using appropriate index and
    thus allow to avoid grouping. For each found row it updates non-aggregated
    fields with values from row with found MIN/MAX value.
    Without loose index scan non-aggregated fields are copied by end_send_group
    function. With loose index scan there is no need in end_send_group and
    end_send is used instead. Non-aggregated fields still need to be copied and
    this was wrongly implemented in QUICK_GROUP_MIN_MAX_SELECT::get_next.
    WL#3220 added a case when loose index scan can be used with end_send_group to
    optimize calculation of aggregate functions with distinct. In this case
    the row found by QUICK_GROUP_MIN_MAX_SELECT::get_next might belong to a next
    group and copying it will produce wrong result.
    
    Update of non-aggregated fields is moved to the end_send function from
    QUICK_GROUP_MIN_MAX_SELECT::get_next.
    
    
    mysql-test/r/group_min_max.result:
      Added a test case for the bug#50539.
    mysql-test/t/group_min_max.test:
      Added a test case for the bug#50539.
    sql/opt_range.cc:
      Bug#50539: Wrong result when loose index scan is used for an aggregate
      function with distinct.
      Update of non-aggregated fields is moved to the end_send function from
      QUICK_GROUP_MIN_MAX_SELECT::get_next.
    sql/sql_select.cc:
      Bug#50539: Wrong result when loose index scan is used for an aggregate
      function with distinct.
      Update of non-aggregated fields is moved to the end_send function from
      QUICK_GROUP_MIN_MAX_SELECT::get_next.
    2d18c5be
group_min_max.result 102 KB