Skip to content

Commit 5b5a67b

Browse files
committed
MDEV-26786 Inserting NULL into base column breaks NATURAL_SORT_KEY column
When returning non-null value from natural_sort_key, make sure Item::null_value is false.
1 parent 6c5c1fd commit 5b5a67b

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

mysql-test/main/natural_sort_key.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,16 @@ pic120 pic2120
190190
pic121 pic2121
191191
pic02000 pic32000
192192
tom tom
193+
create table t (a varchar(8), b varchar(8) as (natural_sort_key(a)));
194+
insert into t (a) values ('a2'),(NULL),('a11');
195+
select * from t order by b;
196+
a b
197+
NULL NULL
198+
a2 a02
199+
a11 a111
200+
select a, b from t order by b;
201+
a b
202+
NULL NULL
203+
a2 a02
204+
a11 a111
205+
drop table t;

mysql-test/main/natural_sort_key.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,10 @@ SELECT RPAD(val,20,' ') value, NATURAL_SORT_KEY(val) FROM
8686
('a01b3')
8787
)AS data ORDER BY 2,1;
8888

89+
# MDEV-27686 (null value indicator not always reset)
90+
create table t (a varchar(8), b varchar(8) as (natural_sort_key(a)));
91+
insert into t (a) values ('a2'),(NULL),('a11');
92+
select * from t order by b;
93+
select a, b from t order by b;
94+
drop table t;
95+

sql/item_strfunc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5682,7 +5682,7 @@ String *Item_func_natural_sort_key::val_str(String *out)
56825682
if (tmp.copy(out, cs, &errs) || out->copy(tmp))
56835683
goto error_exit;
56845684
}
5685-
5685+
null_value= false;
56865686
return out;
56875687

56885688
error_exit:

0 commit comments

Comments
 (0)