diff options
Diffstat (limited to 'sql/uniques.cc')
-rw-r--r-- | sql/uniques.cc | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/sql/uniques.cc b/sql/uniques.cc index 60918ea534e..f5d85bbb5cc 100644 --- a/sql/uniques.cc +++ b/sql/uniques.cc @@ -735,6 +735,13 @@ bool Unique::merge(TABLE *table, uchar *buff, size_t buff_size, sort_param.cmp_context.key_compare= tree.compare; sort_param.cmp_context.key_compare_arg= tree.custom_arg; + /* + We need to remove the size allocated for the unique bufffer. + The sort_buffer_size is: + MY_MAX(MERGEBUFF2+1, max_in_memory_size/full_size+1) * full_size; + */ + buff_size-= full_size; + /* Merge the buffers to one file, removing duplicates */ if (merge_many_buff(&sort_param, Bounds_checked_array<uchar>(buff, buff_size), @@ -802,7 +809,8 @@ bool Unique::get(TABLE *table) /* Not enough memory; Save the result to file && free memory used by tree */ if (flush()) DBUG_RETURN(1); - size_t buff_sz= (max_in_memory_size / full_size + 1) * full_size; + size_t buff_sz= MY_MAX(MERGEBUFF2+1, max_in_memory_size/full_size+1) * full_size; + if (!(sort_buffer= (uchar*) my_malloc(key_memory_Unique_sort_buffer, buff_sz, MYF(MY_THREAD_SPECIFIC|MY_WME)))) DBUG_RETURN(1); |