diff options
author | Varun Gupta <varun.gupta@mariadb.com> | 2020-06-10 18:42:47 +0530 |
---|---|---|
committer | Varun Gupta <varun.gupta@mariadb.com> | 2020-06-10 18:45:34 +0530 |
commit | 9d1809640149fb5b4ce44d1716432726ae085975 (patch) | |
tree | fe3b63f76b4bf46d3a44da4d2e5d8213baae8226 /sql/filesort.cc | |
parent | 648b54746c2dbad98f3e09609e1217be918286dd (diff) | |
download | mariadb-git-10.5-mdev22819.tar.gz |
MDEV-22819: Wrong result or Assertion `ix > 0' failed in read_to_buffer upon select with GROUP BY and GROUP_CONCAT10.5-mdev22819
In the merge_buffers phase for sorting, the sort buffer size is divided between the number of chunks.
The chunks have a start and end position (m_buffer_start and m_buffer_end).
Then we read the as many records that fit in this buffer for a chunk of the file.
The issue here was we were resetting the end of buffer(m_buffer_end) to the number of bytes that was
read, this was causing a problem because with dynamic size of sort keys it is possible that later
we would not be able to accommodate even one key inside a chunk of file.
So the fix was to not reset the end of buffer for a chunk of file.
Diffstat (limited to 'sql/filesort.cc')
-rw-r--r-- | sql/filesort.cc | 8 |
1 files changed, 3 insertions, 5 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); |