diff options
author | Sergei Golubchik <serg@mariadb.org> | 2017-07-12 19:31:01 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2017-07-13 11:23:54 +0200 |
commit | 27bc13b7a2f99a6011a5081670b320c685dde443 (patch) | |
tree | 5716bba31b153158f9fc3321069d0784ed1ff9bd | |
parent | e7f51e5d269ba8adb917226724564274a57d07b3 (diff) | |
download | mariadb-git-27bc13b7a2f99a6011a5081670b320c685dde443.tar.gz |
MDEV-12136 SELECT COUNT(DISTINCT) returns the wrong value when tmp_table_size is limited
Same MDEV, second bug.
Merge buffer must fit at least MERGEBUFF2 (that is, 15) key values.
Because merge_index() can merge that many buffers, and
merge_many_buff() leaves that many buffers unmerged.
-rw-r--r-- | mysql-test/r/count_distinct.result | 4 | ||||
-rw-r--r-- | mysql-test/t/count_distinct.test | 2 | ||||
-rw-r--r-- | sql/uniques.cc | 8 |
3 files changed, 12 insertions, 2 deletions
diff --git a/mysql-test/r/count_distinct.result b/mysql-test/r/count_distinct.result index 3decd5f60bc..d55a232c715 100644 --- a/mysql-test/r/count_distinct.result +++ b/mysql-test/r/count_distinct.result @@ -100,5 +100,9 @@ set @@tmp_table_size = 1024; select count(distinct user_id) from t1; count(distinct user_id) 17 +alter table t1 modify user_id char(128) character set utf8; +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 ac97cdba357..a00574b6cba 100644 --- a/mysql-test/t/count_distinct.test +++ b/mysql-test/t/count_distinct.test @@ -115,6 +115,8 @@ 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; +alter table t1 modify user_id char(128) character set utf8; +select count(distinct user_id) from t1; drop table t1; set @@tmp_table_size = default; diff --git a/sql/uniques.cc b/sql/uniques.cc index f80117065dd..8b7da7e6e52 100644 --- a/sql/uniques.cc +++ b/sql/uniques.cc @@ -607,11 +607,15 @@ bool Unique::walk(TABLE *table, tree_walk_action action, void *walk_action_arg) return 1; if (flush_io_cache(&file) || reinit_io_cache(&file, READ_CACHE, 0L, 0, 0)) return 1; - size_t buff_sz= (max_in_memory_size / full_size + 1) * full_size; + /* + merge_buffer must fit at least MERGEBUFF2 keys, because + merge_index() can merge that many BUFFPEKs at once. + */ + size_t buff_sz= max(MERGEBUFF2, max_in_memory_size/full_size+1) * full_size; if (!(merge_buffer = (uchar *)my_malloc(buff_sz, MYF(MY_WME)))) return 1; if (buff_sz < (ulong) (full_size * (file_ptrs.elements + 1))) - res= merge(table, merge_buffer, buff_sz >= full_size * MERGEBUFF2) ; + res= merge(table, merge_buffer, true) ; if (!res) { |