diff options
author | Sergei Golubchik <serg@mariadb.org> | 2017-07-12 19:20:52 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2017-07-12 19:20:52 +0200 |
commit | e7f51e5d269ba8adb917226724564274a57d07b3 (patch) | |
tree | 0fc76e75f3893aeb28b39faedb24fa073b486a69 | |
parent | 181d9d2892739629382727cf956364106c947ea2 (diff) | |
download | mariadb-git-e7f51e5d269ba8adb917226724564274a57d07b3.tar.gz |
MDEV-12136 SELECT COUNT(DISTINCT) returns the wrong value when tmp_table_size is limited
use the correct value for the merge_buffer size, max_in_memory_size
is too small and merge_walk() fails.
also: remove a cast.
-rw-r--r-- | mysql-test/r/count_distinct.result | 8 | ||||
-rw-r--r-- | mysql-test/t/count_distinct.test | 14 | ||||
-rw-r--r-- | sql/uniques.cc | 6 |
3 files changed, 25 insertions, 3 deletions
diff --git a/mysql-test/r/count_distinct.result b/mysql-test/r/count_distinct.result index 3b65dd0e608..3decd5f60bc 100644 --- a/mysql-test/r/count_distinct.result +++ b/mysql-test/r/count_distinct.result @@ -94,3 +94,11 @@ count(distinct i) 2 drop table t1; drop view v1; +create table t1 (user_id char(64) character set utf8); +insert t1 values(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17); +set @@tmp_table_size = 1024; +select count(distinct user_id) from t1; +count(distinct user_id) +17 +drop table t1; +set @@tmp_table_size = default; diff --git a/mysql-test/t/count_distinct.test b/mysql-test/t/count_distinct.test index 10b4ac6f0e7..ac97cdba357 100644 --- a/mysql-test/t/count_distinct.test +++ b/mysql-test/t/count_distinct.test @@ -107,3 +107,17 @@ create view v1 as select * from t1; select count(distinct i) from v1; drop table t1; drop view v1; + +# +# MDEV-12136 SELECT COUNT(DISTINCT) returns the wrong value when tmp_table_size is limited +# +create table t1 (user_id char(64) character set utf8); +insert t1 values(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17); +set @@tmp_table_size = 1024; +select count(distinct user_id) from t1; +drop table t1; +set @@tmp_table_size = default; + +# +# End of 5.5 tests +# diff --git a/sql/uniques.cc b/sql/uniques.cc index fe3e329cda6..f80117065dd 100644 --- a/sql/uniques.cc +++ b/sql/uniques.cc @@ -461,7 +461,7 @@ C_MODE_END <> 0 error */ -static bool merge_walk(uchar *merge_buffer, ulong merge_buffer_size, +static bool merge_walk(uchar *merge_buffer, size_t merge_buffer_size, uint key_length, BUFFPEK *begin, BUFFPEK *end, tree_walk_action walk_action, void *walk_action_arg, qsort_cmp2 compare, void *compare_arg, @@ -470,7 +470,7 @@ static bool merge_walk(uchar *merge_buffer, ulong merge_buffer_size, BUFFPEK_COMPARE_CONTEXT compare_context = { compare, compare_arg }; QUEUE queue; if (end <= begin || - merge_buffer_size < (ulong) (key_length * (end - begin + 1)) || + merge_buffer_size < (size_t) (key_length * (end - begin + 1)) || init_queue(&queue, (uint) (end - begin), offsetof(BUFFPEK, key), 0, buffpek_compare, &compare_context, 0, 0)) return 1; @@ -615,7 +615,7 @@ bool Unique::walk(TABLE *table, tree_walk_action action, void *walk_action_arg) if (!res) { - res= merge_walk(merge_buffer, (ulong) max_in_memory_size, full_size, + res= merge_walk(merge_buffer, buff_sz, full_size, (BUFFPEK *) file_ptrs.buffer, (BUFFPEK *) file_ptrs.buffer + file_ptrs.elements, action, walk_action_arg, |