1create table t1 (pk int primary key); 2insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); 3select * from t1 order by now(), cast(pk as char(0)); 4pk 51 610 72 83 94 105 116 127 138 149 15show warnings; 16Level Code Message 17Warning 1292 Truncated incorrect CHAR(0) value: '1' 18Warning 1292 Truncated incorrect CHAR(0) value: '2' 19Warning 1292 Truncated incorrect CHAR(0) value: '3' 20Warning 1292 Truncated incorrect CHAR(0) value: '4' 21Warning 1292 Truncated incorrect CHAR(0) value: '5' 22Warning 1292 Truncated incorrect CHAR(0) value: '6' 23Warning 1292 Truncated incorrect CHAR(0) value: '7' 24Warning 1292 Truncated incorrect CHAR(0) value: '8' 25Warning 1292 Truncated incorrect CHAR(0) value: '9' 26Warning 1292 Truncated incorrect CHAR(0) value: '10' 27drop table t1; 28# 29# MDEV-17020: Assertion `length > 0' failed in ptr_compare upon ORDER BY with bad conversion 30# 31set @save_sql_mode= @@sql_mode; 32SET @@sql_mode= ''; 33CREATE TABLE t1 (pk INT PRIMARY KEY); 34INSERT INTO t1 VALUES (1),(2); 35explain 36SELECT * FROM t1 ORDER BY 'foo', CONVERT(pk, CHAR(0)) LIMIT 2; 37id select_type table type possible_keys key key_len ref rows Extra 381 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using index; Using filesort 39SELECT * FROM t1 ORDER BY 'foo', Cast(pk as CHAR(0)) LIMIT 2; 40pk 411 422 43Warnings: 44Warning 1292 Truncated incorrect CHAR(0) value: '1' 45Warning 1292 Truncated incorrect CHAR(0) value: '2' 46set @@sql_mode= @save_sql_mode; 47drop table t1; 48