summaryrefslogtreecommitdiff
path: root/sql/opt_range.cc
diff options
context:
space:
mode:
authorEvgeny Potemkin <epotemkin@mysql.com>2010-02-12 11:51:52 +0300
committerEvgeny Potemkin <epotemkin@mysql.com>2010-02-12 11:51:52 +0300
commit3e0f70d2cc0d233f0be615532ed3a5254930ad17 (patch)
tree7e0ebfd00145b87e6233078f7d11b1e3517fa668 /sql/opt_range.cc
parent97afccae53a5fda90311f57d328924d736279414 (diff)
downloadmariadb-git-3e0f70d2cc0d233f0be615532ed3a5254930ad17.tar.gz
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. 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.
Diffstat (limited to 'sql/opt_range.cc')
-rw-r--r--sql/opt_range.cc12
1 files changed, 1 insertions, 11 deletions
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index ac5b1f575de..5c64a6a64ee 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -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);