summaryrefslogtreecommitdiff
path: root/sql/uniques.cc
diff options
context:
space:
mode:
authorVarun Gupta <varunraiko1803@gmail.com>2017-08-08 21:13:45 +0530
committerVarun Gupta <varunraiko1803@gmail.com>2017-08-09 18:09:04 +0530
commit0739179857699d68758ff2e56e9414735546ded6 (patch)
tree53568b508da617154d5cb0747e21a4400bdcd421 /sql/uniques.cc
parentc8a0244e957bc4beff453f09c881bb51752d682c (diff)
downloadmariadb-git-0739179857699d68758ff2e56e9414735546ded6.tar.gz
MDEV-13458: Wrong result for aggregate function with distinct clause when the value for tmp_table_size is small
Fixed by making sure that the sort buffer would have atleast MERGEBUFF2 keys. Also fixed MDEV-13457 by making sure that an empty tree is never dumped to the disk
Diffstat (limited to 'sql/uniques.cc')
-rw-r--r--sql/uniques.cc12
1 files changed, 8 insertions, 4 deletions
diff --git a/sql/uniques.cc b/sql/uniques.cc
index 8b7da7e6e52..89ab4682829 100644
--- a/sql/uniques.cc
+++ b/sql/uniques.cc
@@ -96,6 +96,9 @@ Unique::Unique(qsort_cmp2 comp_func, void * comp_func_fixed_arg,
*/
max_elements= (ulong) (max_in_memory_size /
ALIGN_SIZE(sizeof(TREE_ELEMENT)+size));
+ if (!max_elements)
+ max_elements= 1;
+
(void) open_cached_file(&file, mysql_tmpdir,TEMP_PREFIX, DISK_BUFFER_SIZE,
MYF(MY_WME));
}
@@ -608,10 +611,11 @@ bool Unique::walk(TABLE *table, tree_walk_action action, void *walk_action_arg)
if (flush_io_cache(&file) || reinit_io_cache(&file, READ_CACHE, 0L, 0, 0))
return 1;
/*
- merge_buffer must fit at least MERGEBUFF2 keys, because
- merge_index() can merge that many BUFFPEKs at once.
+ merge_buffer must fit at least MERGEBUFF2 + 1 keys, because
+ merge_index() can merge that many BUFFPEKs at once. The extra space for one key
+ is needed when a piece of merge buffer is re-read, see merge_walk()
*/
- size_t buff_sz= max(MERGEBUFF2, max_in_memory_size/full_size+1) * full_size;
+ size_t buff_sz= max(MERGEBUFF2+1, 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)))
@@ -673,7 +677,7 @@ bool Unique::merge(TABLE *table, uchar *buff, bool without_last_merge)
full_size;
sort_param.min_dupl_count= min_dupl_count;
sort_param.res_length= 0;
- sort_param.keys= (uint) (max_in_memory_size / sort_param.sort_length);
+ sort_param.keys= (uint) max((max_in_memory_size / sort_param.sort_length), MERGEBUFF2);
sort_param.not_killable= 1;
sort_param.unique_buff= buff + (sort_param.keys * sort_param.sort_length);