summaryrefslogtreecommitdiff
path: root/sql/uniques.cc
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <vicentiu@mariadb.org>2017-09-19 12:43:02 +0300
committerVicențiu Ciorbaru <vicentiu@mariadb.org>2017-09-19 12:43:02 +0300
commit22c322c649d5a15e3bb731d6751a0d80c8ec23b0 (patch)
tree11073f6169c237da226a977736d234c7c7b5c163 /sql/uniques.cc
parent7d49aab32c3733f26cff8d83396a65bd120352e8 (diff)
parentec6042bda097fa53c43caf4a1acc32c5a77f6ed4 (diff)
downloadmariadb-git-22c322c649d5a15e3bb731d6751a0d80c8ec23b0.tar.gz
Merge branch '10.1' into 10.2
Diffstat (limited to 'sql/uniques.cc')
-rw-r--r--sql/uniques.cc16
1 files changed, 10 insertions, 6 deletions
diff --git a/sql/uniques.cc b/sql/uniques.cc
index 71d2093b828..338f7c7c537 100644
--- a/sql/uniques.cc
+++ b/sql/uniques.cc
@@ -101,6 +101,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));
}
@@ -646,11 +649,12 @@ 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= MY_MAX(MERGEBUFF2, max_in_memory_size/full_size+1) * full_size;
- if (!(merge_buffer = (uchar *)my_malloc(buff_sz, MYF(MY_THREAD_SPECIFIC|MY_WME))))
+ size_t buff_sz= MY_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 < full_size * (file_ptrs.elements + 1UL))
res= merge(table, merge_buffer, buff_sz >= full_size * MERGEBUFF2) ;
@@ -708,8 +712,8 @@ 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.max_keys_per_buffer=
- (uint) (max_in_memory_size / sort_param.sort_length);
+ sort_param.max_keys_per_buffer=
+ (uint) MY_MAX((max_in_memory_size / sort_param.sort_length), MERGEBUFF2);
sort_param.not_killable= 1;
sort_param.unique_buff= buff +(sort_param.max_keys_per_buffer *