[Commits] b46e58ffb82: MDEV-21044: Wrong result when using a smaller size for sort buffer

Varun varunraiko1803 at gmail.com
Fri Nov 15 09:08:43 EET 2019


revision-id: b46e58ffb828e90c83e3b1ee536b0e6d345570c6 (mariadb-10.1.41-92-gb46e58ffb82)
parent(s): 214023aa0e6ec00dcac386167a2b2cf9394b6c7e
author: Varun Gupta
committer: Varun Gupta
timestamp: 2019-11-15 12:33:32 +0530
message:

MDEV-21044: Wrong result when using a smaller size for sort buffer

Make sure that the sort buffers can store atleast one sort key.
This is needed to make sure that all merge buffers are read else
with no sort keys some merge buffers are skipped because the code
makes a conclusion there is no data to be read.

---
 mysql-test/r/order_by.result | 30 ++++++++++++++++++++++++++++++
 mysql-test/t/order_by.test   | 16 ++++++++++++++++
 sql/filesort.cc              |  1 +
 3 files changed, 47 insertions(+)

diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result
index 4cd9aebdf49..380687554d7 100644
--- a/mysql-test/r/order_by.result
+++ b/mysql-test/r/order_by.result
@@ -3207,3 +3207,33 @@ pk
 2
 3
 DROP TABLE t1;
+#
+# MDEV-21044: Wrong result when using a smaller size for sort buffer
+#
+create table t1(a varchar(765),b int);
+insert into t1 values ("a",1),("b",2),("c",3),("e",4);
+insert into t1 values ("d",5),("f",6),("g",7),("h",8);
+insert into t1 values ("k",11),("l",12),("i",9),("j",10);
+insert into t1 values ("m",13),("n",14),("o",15),("p",16);
+set @save_sort_buffer_size= @@sort_buffer_size;
+set sort_buffer_size=1024;
+select * from t1 order  by b;
+a	b
+a	1
+b	2
+c	3
+e	4
+d	5
+f	6
+g	7
+h	8
+i	9
+j	10
+k	11
+l	12
+m	13
+n	14
+o	15
+p	16
+set @@sort_buffer_size= @save_sort_buffer_size;
+drop table t1;
diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test
index 1ca258d1d48..999c7314139 100644
--- a/mysql-test/t/order_by.test
+++ b/mysql-test/t/order_by.test
@@ -2141,3 +2141,19 @@ INSERT INTO t1 VALUES (1),(2),(3);
 SELECT DISTINCT pk FROM t1 GROUP BY 'foo';
 SELECT DISTINCT pk FROM t1;
 DROP TABLE t1;
+
+--echo #
+--echo # MDEV-21044: Wrong result when using a smaller size for sort buffer
+--echo #
+
+create table t1(a varchar(765),b int);
+insert into t1 values ("a",1),("b",2),("c",3),("e",4);
+insert into t1 values ("d",5),("f",6),("g",7),("h",8);
+insert into t1 values ("k",11),("l",12),("i",9),("j",10);
+insert into t1 values ("m",13),("n",14),("o",15),("p",16);
+set @save_sort_buffer_size= @@sort_buffer_size;
+set sort_buffer_size=1024;
+select * from t1 order  by b;
+set @@sort_buffer_size= @save_sort_buffer_size;
+drop table t1;
+
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 4f195f68059..bb3e73343ad 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -343,6 +343,7 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
     param.max_keys_per_buffer=((param.max_keys_per_buffer *
                                 (param.rec_length + sizeof(char*))) /
                                param.rec_length - 1);
+    set_if_bigger(param.max_keys_per_buffer, 1);
     maxbuffer--;				// Offset from 0
     if (merge_many_buff(&param,
                         (uchar*) table_sort.get_sort_keys(),


More information about the commits mailing list