1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

Bug#50539: Wrong result when loose index scan is used for an aggregate

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.
This commit is contained in:
Evgeny Potemkin
2010-02-12 11:51:52 +03:00
parent 6bad45745c
commit b5f40f3454
4 changed files with 50 additions and 14 deletions

View File

@ -10959,17 +10959,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::get_next()
} while ((result == HA_ERR_KEY_NOT_FOUND || result == HA_ERR_END_OF_FILE) &&
is_last_prefix != 0);
if (result == 0)
{
/*
Partially mimic the behavior of end_select_send. Copy the
field data from Item_field::field into Item_field::result_field
of each non-aggregated field (the group fields, and optionally
other fields in non-ANSI SQL mode).
*/
copy_fields(&join->tmp_table_param);
}
else if (result == HA_ERR_KEY_NOT_FOUND)
if (result == HA_ERR_KEY_NOT_FOUND)
result= HA_ERR_END_OF_FILE;
DBUG_RETURN(result);