summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/filesort.cc8
-rw-r--r--sql/uniques.cc10
2 files changed, 12 insertions, 6 deletions
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 6fa9b192655..ac43c96b0e0 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -1845,17 +1845,15 @@ bool merge_buffers(Sort_param *param, IO_CACHE *from_file,
offsetof(Merge_chunk,m_current_key), 0,
(queue_compare) cmp, first_cmp_arg, 0, 0)))
DBUG_RETURN(1); /* purecov: inspected */
+ const size_t chunk_sz = (sort_buffer.size()/((uint) (Tb-Fb) +1));
for (buffpek= Fb ; buffpek <= Tb ; buffpek++)
{
- buffpek->set_buffer(strpos,
- strpos + (sort_buffer.size()/((uint) (Tb-Fb) +1)));
-
+ buffpek->set_buffer(strpos, strpos + chunk_sz);
buffpek->set_max_keys(maxcount);
bytes_read= read_to_buffer(from_file, buffpek, param, packed_format);
if (unlikely(bytes_read == (ulong) -1))
goto err; /* purecov: inspected */
- strpos+= bytes_read;
- buffpek->set_buffer_end(strpos);
+ strpos+= chunk_sz;
// If less data in buffers than expected
buffpek->set_max_keys(buffpek->mem_count());
queue_insert(&queue, (uchar*) buffpek);
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);