diff options
23 files changed, 138 insertions, 47 deletions
diff --git a/mysql-test/include/ctype_utf8mb4.inc b/mysql-test/include/ctype_utf8mb4.inc index edd58ee32e7..862afe96f6c 100644 --- a/mysql-test/include/ctype_utf8mb4.inc +++ b/mysql-test/include/ctype_utf8mb4.inc @@ -1585,7 +1585,7 @@ drop table t1; --echo # --echo # Check strnxfrm() with odd length --echo # -set max_sort_length=5; +set max_sort_length=9; select @@max_sort_length; eval create table t1 (a varchar(128) character set utf8mb4 collate utf8mb4_general_ci) engine $engine; insert into t1 values ('a'),('b'),('c'); diff --git a/mysql-test/r/ctype_utf16.result b/mysql-test/r/ctype_utf16.result index 371ccc01a22..491e01b7361 100644 --- a/mysql-test/r/ctype_utf16.result +++ b/mysql-test/r/ctype_utf16.result @@ -1491,7 +1491,7 @@ ab ab AE AE -SET max_sort_length=4; +SET max_sort_length=8; SELECT * FROM t1 ORDER BY s1; s1 ab diff --git a/mysql-test/r/ctype_utf16le.result b/mysql-test/r/ctype_utf16le.result index a9e5cd5a417..d98c113840b 100644 --- a/mysql-test/r/ctype_utf16le.result +++ b/mysql-test/r/ctype_utf16le.result @@ -1764,7 +1764,7 @@ ab ab AE AE -SET max_sort_length=4; +SET max_sort_length=8; SELECT * FROM t1 ORDER BY s1; s1 ab diff --git a/mysql-test/r/ctype_utf32.result b/mysql-test/r/ctype_utf32.result index 20395d26da0..8f40a90859b 100644 --- a/mysql-test/r/ctype_utf32.result +++ b/mysql-test/r/ctype_utf32.result @@ -1504,7 +1504,7 @@ ab ab AE AE -SET max_sort_length=4; +SET max_sort_length=8; SELECT * FROM t1 ORDER BY s1; s1 ab diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 5ffed278f83..ed61dfda217 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -6754,10 +6754,10 @@ DFFFDFFF9CFF9DFF9EFF # # Checking strnxfrm() with odd length # -set max_sort_length=5; +set max_sort_length=9; select @@max_sort_length; @@max_sort_length -5 +9 create table t1 (a varchar(128) character set utf8 collate utf8_general_ci); insert into t1 values ('a'),('b'),('c'); select * from t1 order by a; diff --git a/mysql-test/r/ctype_utf8mb4.result b/mysql-test/r/ctype_utf8mb4.result index b0777a0b9f0..691ac51e241 100644 --- a/mysql-test/r/ctype_utf8mb4.result +++ b/mysql-test/r/ctype_utf8mb4.result @@ -2371,10 +2371,10 @@ drop table t1; # # Check strnxfrm() with odd length # -set max_sort_length=5; +set max_sort_length=9; select @@max_sort_length; @@max_sort_length -5 +9 create table t1 (a varchar(128) character set utf8mb4 collate utf8mb4_general_ci); insert into t1 values ('a'),('b'),('c'); select * from t1 order by a; diff --git a/mysql-test/r/ctype_utf8mb4_heap.result b/mysql-test/r/ctype_utf8mb4_heap.result index 127b72674ac..4aef2d8cb66 100644 --- a/mysql-test/r/ctype_utf8mb4_heap.result +++ b/mysql-test/r/ctype_utf8mb4_heap.result @@ -2203,10 +2203,10 @@ drop table t1; # # Check strnxfrm() with odd length # -set max_sort_length=5; +set max_sort_length=9; select @@max_sort_length; @@max_sort_length -5 +9 create table t1 (a varchar(128) character set utf8mb4 collate utf8mb4_general_ci) engine heap; insert into t1 values ('a'),('b'),('c'); select * from t1 order by a; diff --git a/mysql-test/r/ctype_utf8mb4_innodb.result b/mysql-test/r/ctype_utf8mb4_innodb.result index bce039d436f..7c95906a742 100644 --- a/mysql-test/r/ctype_utf8mb4_innodb.result +++ b/mysql-test/r/ctype_utf8mb4_innodb.result @@ -2331,10 +2331,10 @@ drop table t1; # # Check strnxfrm() with odd length # -set max_sort_length=5; +set max_sort_length=9; select @@max_sort_length; @@max_sort_length -5 +9 create table t1 (a varchar(128) character set utf8mb4 collate utf8mb4_general_ci) engine InnoDB; insert into t1 values ('a'),('b'),('c'); select * from t1 order by a; diff --git a/mysql-test/r/ctype_utf8mb4_myisam.result b/mysql-test/r/ctype_utf8mb4_myisam.result index b834448b2fd..f06a1fc53f3 100644 --- a/mysql-test/r/ctype_utf8mb4_myisam.result +++ b/mysql-test/r/ctype_utf8mb4_myisam.result @@ -2331,10 +2331,10 @@ drop table t1; # # Check strnxfrm() with odd length # -set max_sort_length=5; +set max_sort_length=9; select @@max_sort_length; @@max_sort_length -5 +9 create table t1 (a varchar(128) character set utf8mb4 collate utf8mb4_general_ci) engine MyISAM; insert into t1 values ('a'),('b'),('c'); select * from t1 order by a; diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result index e739b278746..91f2d21776a 100644 --- a/mysql-test/r/order_by.result +++ b/mysql-test/r/order_by.result @@ -3236,6 +3236,71 @@ p 16 set @@sort_buffer_size= @save_sort_buffer_size; drop table t1; # +# MDEV-22715: SIGSEGV in radixsort_for_str_ptr and in native_compare/my_qsort2 (optimized builds) +# +SET @save_sort_buffer_size= @@sort_buffer_size; +SET @save_max_sort_length= @@max_sort_length; +SET max_sort_length=8; +SET sort_buffer_size=1024; +CREATE TABLE t1(a INT, b DECIMAL(65), c BLOB); +INSERT INTO t1 SELECT seq, seq, seq from seq_1_to_25; +INSERT INTO t1 SELECT seq, seq, seq from seq_1_to_25; +SELECT * FROM t1 ORDER BY a,b; +a b c +1 1 1 +1 1 1 +2 2 2 +2 2 2 +3 3 3 +3 3 3 +4 4 4 +4 4 4 +5 5 5 +5 5 5 +6 6 6 +6 6 6 +7 7 7 +7 7 7 +8 8 8 +8 8 8 +9 9 9 +9 9 9 +10 10 10 +10 10 10 +11 11 11 +11 11 11 +12 12 12 +12 12 12 +13 13 13 +13 13 13 +14 14 14 +14 14 14 +15 15 15 +15 15 15 +16 16 16 +16 16 16 +17 17 17 +17 17 17 +18 18 18 +18 18 18 +19 19 19 +19 19 19 +20 20 20 +20 20 20 +21 21 21 +21 21 21 +22 22 22 +22 22 22 +23 23 23 +23 23 23 +24 24 24 +24 24 24 +25 25 25 +25 25 25 +SET @@sort_buffer_size= @save_sort_buffer_size; +SET @@max_sort_length= @save_max_sort_length; +DROP TABLE t1; +# # MDEV-13994: Bad join results with orderby_uses_equalities=on # CREATE TABLE books ( @@ -3296,3 +3361,4 @@ NULLIF(GROUP_CONCAT(v1), null) C B DROP TABLE t1; +# End of 10.2 tests diff --git a/mysql-test/suite/sys_vars/r/max_sort_length_basic.result b/mysql-test/suite/sys_vars/r/max_sort_length_basic.result index a8876b2c81e..b48b045897c 100644 --- a/mysql-test/suite/sys_vars/r/max_sort_length_basic.result +++ b/mysql-test/suite/sys_vars/r/max_sort_length_basic.result @@ -27,14 +27,14 @@ SELECT @@session.max_sort_length = 1024; @@session.max_sort_length = 1024 1 '#--------------------FN_DYNVARS_084_03-------------------------#' -SET @@global.max_sort_length = 4; +SET @@global.max_sort_length = 8; SELECT @@global.max_sort_length; @@global.max_sort_length -4 -SET @@global.max_sort_length = 5; +8 +SET @@global.max_sort_length = 9; SELECT @@global.max_sort_length; @@global.max_sort_length -5 +9 SET @@global.max_sort_length = 8388608; SELECT @@global.max_sort_length; @@global.max_sort_length @@ -48,14 +48,14 @@ SELECT @@global.max_sort_length; @@global.max_sort_length 65536 '#--------------------FN_DYNVARS_084_04-------------------------#' -SET @@session.max_sort_length = 4; +SET @@session.max_sort_length = 8; SELECT @@session.max_sort_length; @@session.max_sort_length -4 -SET @@session.max_sort_length = 5; +8 +SET @@session.max_sort_length = 9; SELECT @@session.max_sort_length; @@session.max_sort_length -5 +9 SET @@session.max_sort_length = 8388608; SELECT @@session.max_sort_length; @@session.max_sort_length @@ -74,13 +74,13 @@ Warnings: Warning 1292 Truncated incorrect max_sort_length value: '-1024' SELECT @@global.max_sort_length; @@global.max_sort_length -4 +8 SET @@global.max_sort_length = 3; Warnings: Warning 1292 Truncated incorrect max_sort_length value: '3' SELECT @@global.max_sort_length; @@global.max_sort_length -4 +8 SET @@global.max_sort_length = 8388609; Warnings: Warning 1292 Truncated incorrect max_sort_length value: '8388609' @@ -92,17 +92,17 @@ Warnings: Warning 1292 Truncated incorrect max_sort_length value: '0' SELECT @@global.max_sort_length; @@global.max_sort_length -4 +8 SET @@global.max_sort_length = 65530.34; ERROR 42000: Incorrect argument type to variable 'max_sort_length' SELECT @@global.max_sort_length; @@global.max_sort_length -4 +8 SET @@global.max_sort_length = test; ERROR 42000: Incorrect argument type to variable 'max_sort_length' SELECT @@global.max_sort_length; @@global.max_sort_length -4 +8 SET @@session.max_sort_length = 8388610; Warnings: Warning 1292 Truncated incorrect max_sort_length value: '8388610' @@ -114,19 +114,19 @@ Warnings: Warning 1292 Truncated incorrect max_sort_length value: '-1' SELECT @@session.max_sort_length; @@session.max_sort_length -4 +8 SET @@session.max_sort_length = 3; Warnings: Warning 1292 Truncated incorrect max_sort_length value: '3' SELECT @@session.max_sort_length; @@session.max_sort_length -4 +8 SET @@session.max_sort_length = 0; Warnings: Warning 1292 Truncated incorrect max_sort_length value: '0' SELECT @@session.max_sort_length; @@session.max_sort_length -4 +8 SET @@session.max_sort_length = 65530.34; ERROR 42000: Incorrect argument type to variable 'max_sort_length' SET @@session.max_sort_length = 10737418241; @@ -158,13 +158,13 @@ Warnings: Warning 1292 Truncated incorrect max_sort_length value: '1' SELECT @@global.max_sort_length; @@global.max_sort_length -4 +8 SET @@global.max_sort_length = FALSE; Warnings: Warning 1292 Truncated incorrect max_sort_length value: '0' SELECT @@global.max_sort_length; @@global.max_sort_length -4 +8 '#---------------------FN_DYNVARS_084_09----------------------#' SET @@global.max_sort_length = 2048; SELECT @@max_sort_length = @@global.max_sort_length; diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result index 577b5a97baf..8221a64472b 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result @@ -1766,7 +1766,7 @@ VARIABLE_NAME MAX_SORT_LENGTH VARIABLE_SCOPE SESSION VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT The number of bytes to use when sorting BLOB or TEXT values (only the first max_sort_length bytes of each value are used; the rest are ignored) -NUMERIC_MIN_VALUE 4 +NUMERIC_MIN_VALUE 8 NUMERIC_MAX_VALUE 8388608 NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result index 1dc95c59606..f9c92b91d86 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result @@ -1906,7 +1906,7 @@ VARIABLE_NAME MAX_SORT_LENGTH VARIABLE_SCOPE SESSION VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_COMMENT The number of bytes to use when sorting BLOB or TEXT values (only the first max_sort_length bytes of each value are used; the rest are ignored) -NUMERIC_MIN_VALUE 4 +NUMERIC_MIN_VALUE 8 NUMERIC_MAX_VALUE 8388608 NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL diff --git a/mysql-test/suite/sys_vars/t/max_sort_length_basic.test b/mysql-test/suite/sys_vars/t/max_sort_length_basic.test index 9c3b88d3c3c..fcd6db017f1 100644 --- a/mysql-test/suite/sys_vars/t/max_sort_length_basic.test +++ b/mysql-test/suite/sys_vars/t/max_sort_length_basic.test @@ -74,9 +74,9 @@ SELECT @@session.max_sort_length = 1024; # Change the value of max_sort_length to a valid value for GLOBAL Scope # ######################################################################### -SET @@global.max_sort_length = 4; +SET @@global.max_sort_length = 8; SELECT @@global.max_sort_length; -SET @@global.max_sort_length = 5; +SET @@global.max_sort_length = 9; SELECT @@global.max_sort_length; SET @@global.max_sort_length = 8388608; SELECT @@global.max_sort_length; @@ -90,10 +90,10 @@ SELECT @@global.max_sort_length; # Change the value of max_sort_length to a valid value for SESSION Scope # ########################################################################## -SET @@session.max_sort_length = 4; +SET @@session.max_sort_length = 8; SELECT @@session.max_sort_length; -SET @@session.max_sort_length = 5; +SET @@session.max_sort_length = 9; SELECT @@session.max_sort_length; SET @@session.max_sort_length = 8388608; diff --git a/mysql-test/t/ctype_utf16.test b/mysql-test/t/ctype_utf16.test index 0e497b7b7bd..67442594bb5 100644 --- a/mysql-test/t/ctype_utf16.test +++ b/mysql-test/t/ctype_utf16.test @@ -723,7 +723,7 @@ CREATE TABLE t1 AS SELECT repeat('a',2) as s1 LIMIT 0; SHOW CREATE TABLE t1; INSERT INTO t1 VALUES ('ab'),('AE'),('ab'),('AE'); SELECT * FROM t1 ORDER BY s1; -SET max_sort_length=4; +SET max_sort_length=8; SELECT * FROM t1 ORDER BY s1; DROP TABLE t1; SET max_sort_length=DEFAULT; diff --git a/mysql-test/t/ctype_utf16le.test b/mysql-test/t/ctype_utf16le.test index b8728b52db2..204df136274 100644 --- a/mysql-test/t/ctype_utf16le.test +++ b/mysql-test/t/ctype_utf16le.test @@ -685,7 +685,7 @@ CREATE TABLE t1 AS SELECT REPEAT('a',2) as s1 LIMIT 0; SHOW CREATE TABLE t1; INSERT INTO t1 VALUES ('ab'),('AE'),('ab'),('AE'); SELECT * FROM t1 ORDER BY s1; -SET max_sort_length=4; +SET max_sort_length=8; SELECT * FROM t1 ORDER BY s1; DROP TABLE t1; SET max_sort_length=DEFAULT; diff --git a/mysql-test/t/ctype_utf32.test b/mysql-test/t/ctype_utf32.test index 9821b5de5b2..891fd14d15f 100644 --- a/mysql-test/t/ctype_utf32.test +++ b/mysql-test/t/ctype_utf32.test @@ -779,7 +779,7 @@ CREATE TABLE t1 AS SELECT repeat('a',2) as s1 LIMIT 0; SHOW CREATE TABLE t1; INSERT INTO t1 VALUES ('ab'),('AE'),('ab'),('AE'); SELECT * FROM t1 ORDER BY s1; -SET max_sort_length=4; +SET max_sort_length=8; SELECT * FROM t1 ORDER BY s1; DROP TABLE t1; SET max_sort_length=DEFAULT; diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 3e82f74a38a..b18bd0c8e23 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -1767,7 +1767,7 @@ set @@collation_connection=utf8_bin; --echo # --echo # Checking strnxfrm() with odd length --echo # -set max_sort_length=5; +set max_sort_length=9; select @@max_sort_length; create table t1 (a varchar(128) character set utf8 collate utf8_general_ci); insert into t1 values ('a'),('b'),('c'); diff --git a/mysql-test/t/ctype_utf8mb4.test b/mysql-test/t/ctype_utf8mb4.test index 88fb3d23b62..532729dafde 100644 --- a/mysql-test/t/ctype_utf8mb4.test +++ b/mysql-test/t/ctype_utf8mb4.test @@ -1520,7 +1520,7 @@ drop table t1; --echo # --echo # Check strnxfrm() with odd length --echo # -set max_sort_length=5; +set max_sort_length=9; select @@max_sort_length; create table t1 (a varchar(128) character set utf8mb4 collate utf8mb4_general_ci); insert into t1 values ('a'),('b'),('c'); diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test index 78c16a0cd4c..b2299ae98ec 100644 --- a/mysql-test/t/order_by.test +++ b/mysql-test/t/order_by.test @@ -14,6 +14,8 @@ call mtr.add_suppression("Out of sort memory; increase server sort buffer size") # Test old ORDER BY bug # +--source include/have_sequence.inc + CREATE TABLE t1 ( id int(6) DEFAULT '0' NOT NULL, idservice int(5), @@ -2160,6 +2162,21 @@ select * from t1 order by b; set @@sort_buffer_size= @save_sort_buffer_size; drop table t1; +--echo # +--echo # MDEV-22715: SIGSEGV in radixsort_for_str_ptr and in native_compare/my_qsort2 (optimized builds) +--echo # + +SET @save_sort_buffer_size= @@sort_buffer_size; +SET @save_max_sort_length= @@max_sort_length; +SET max_sort_length=8; +SET sort_buffer_size=1024; +CREATE TABLE t1(a INT, b DECIMAL(65), c BLOB); +INSERT INTO t1 SELECT seq, seq, seq from seq_1_to_25; +INSERT INTO t1 SELECT seq, seq, seq from seq_1_to_25; +SELECT * FROM t1 ORDER BY a,b; +SET @@sort_buffer_size= @save_sort_buffer_size; +SET @@max_sort_length= @save_max_sort_length; +DROP TABLE t1; --echo # --echo # MDEV-13994: Bad join results with orderby_uses_equalities=on @@ -2217,3 +2234,5 @@ GROUP BY id ORDER BY id+1 DESC; DROP TABLE t1; + +--echo # End of 10.2 tests diff --git a/sql/field.cc b/sql/field.cc index d1bd5860f06..1ea7b30f85d 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -3507,10 +3507,9 @@ int Field_new_decimal::cmp(const uchar *a,const uchar*b) } -void Field_new_decimal::sort_string(uchar *buff, - uint length __attribute__((unused))) +void Field_new_decimal::sort_string(uchar *buff, uint length) { - memcpy(buff, ptr, bin_size); + memcpy(buff, ptr, length); } diff --git a/sql/field.h b/sql/field.h index 3007e666ba7..d5e2cb25788 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1218,6 +1218,13 @@ public: void make_sort_key(uchar *buff, uint length); virtual void make_field(Send_field *); + + /* + Some implementations actually may write up to 8 bytes regardless of what + size was requested. This is due to the minimum value of the system variable + max_sort_length. + */ + virtual void sort_string(uchar *buff,uint length)=0; virtual bool optimize_range(uint idx, uint part); virtual void free() {} diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 8eb75e49d8e..2d40943827f 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -2224,7 +2224,7 @@ static Sys_var_ulong Sys_max_sort_length( "the first max_sort_length bytes of each value are used; the rest " "are ignored)", SESSION_VAR(max_sort_length), CMD_LINE(REQUIRED_ARG), - VALID_RANGE(4, 8192*1024L), DEFAULT(1024), BLOCK_SIZE(1)); + VALID_RANGE(8, 8192*1024L), DEFAULT(1024), BLOCK_SIZE(1)); static Sys_var_ulong Sys_max_sp_recursion_depth( "max_sp_recursion_depth", |