diff --git a/mysql-test/main/natural_sort_key.result b/mysql-test/main/natural_sort_key.result index a99fa7a71b8..10adc7acef3 100644 --- a/mysql-test/main/natural_sort_key.result +++ b/mysql-test/main/natural_sort_key.result @@ -190,3 +190,16 @@ pic120 pic2120 pic121 pic2121 pic02000 pic32000 tom tom +create table t (a varchar(8), b varchar(8) as (natural_sort_key(a))); +insert into t (a) values ('a2'),(NULL),('a11'); +select * from t order by b; +a b +NULL NULL +a2 a02 +a11 a111 +select a, b from t order by b; +a b +NULL NULL +a2 a02 +a11 a111 +drop table t; diff --git a/mysql-test/main/natural_sort_key.test b/mysql-test/main/natural_sort_key.test index dda25c9e1f8..4f4e2b0e05e 100644 --- a/mysql-test/main/natural_sort_key.test +++ b/mysql-test/main/natural_sort_key.test @@ -86,3 +86,10 @@ SELECT RPAD(val,20,' ') value, NATURAL_SORT_KEY(val) FROM ('a01b3') )AS data ORDER BY 2,1; +# MDEV-27686 (null value indicator not always reset) +create table t (a varchar(8), b varchar(8) as (natural_sort_key(a))); +insert into t (a) values ('a2'),(NULL),('a11'); +select * from t order by b; +select a, b from t order by b; +drop table t; + diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 60e2d297459..f43115fef54 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -5682,7 +5682,7 @@ String *Item_func_natural_sort_key::val_str(String *out) if (tmp.copy(out, cs, &errs) || out->copy(tmp)) goto error_exit; } - + null_value= false; return out; error_exit: