summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2021-10-07 19:52:18 +0200
committerVladislav Vaintroub <wlad@mariadb.com>2021-10-07 19:52:18 +0200
commit50d54ba961f8c3c0feec08a83c4ed576fc314ce8 (patch)
tree6a79e431d753d3891004dd86b1b95bb63a1ee3e2
parentdeac988668644b0415b4a4724eb577a34f76044b (diff)
downloadmariadb-git-preview-10.7-MDEV-4742-natural-sort-fix.tar.gz
MDEV-26786 Inserting NULL into base column breaks NATURAL_SORT_KEY columnpreview-10.7-MDEV-4742-natural-sort-fix
When returning non-null value from natural_sort_key, make sure Item::null_value is false.
-rw-r--r--mysql-test/main/natural_sort_key.result13
-rw-r--r--mysql-test/main/natural_sort_key.test7
-rw-r--r--sql/item_strfunc.cc2
3 files changed, 21 insertions, 1 deletions
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 976b8b7e10e..9c22c564438 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -5543,7 +5543,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: