From edc75c9c16bbeb2d15fd21c2e458f0b5d90d1ed9 Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Sat, 3 Dec 2016 12:11:06 +0400 Subject: [PATCH] MDEV-11450 Assertion `!null_value' failed invirtual bool Item::send on json_search. Item_func_json_search::val_str didn't set the null_value properly. So that affected the next record in the resultset. --- mysql-test/r/func_json.result | 9 +++++++++ mysql-test/t/func_json.test | 6 ++++++ sql/item_jsonfunc.cc | 6 +++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index c7e6e2f7374..53a1dfbfcf9 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -217,6 +217,15 @@ json_search(@j, 'all', '10', NULL, '$[*]') select json_search(@j, 'all', '10', NULL, '$[*][0].k'); json_search(@j, 'all', '10', NULL, '$[*][0].k') "$[1][0].k" +create table t1( json_col text ); +insert into t1 values +('{ "a": "foobar" }'), +('{ "a": "foobar", "b": "focus", "c": [ "arm", "foot", "shoulder" ] }'); +select json_search( json_col, 'all', 'foot' ) from t1; +json_search( json_col, 'all', 'foot' ) +NULL +"$.c[1]" +drop table t1; select json_unquote('"abc"'); json_unquote('"abc"') abc diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index 6f382512998..e84d5324438 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -92,6 +92,12 @@ select json_search(@j, 'all', 'abc', NULL, '$'); select json_search(@j, 'all', '10', NULL, '$'); select json_search(@j, 'all', '10', NULL, '$[*]'); select json_search(@j, 'all', '10', NULL, '$[*][0].k'); +create table t1( json_col text ); +insert into t1 values +('{ "a": "foobar" }'), + ('{ "a": "foobar", "b": "focus", "c": [ "arm", "foot", "shoulder" ] }'); +select json_search( json_col, 'all', 'foot' ) from t1; +drop table t1; select json_unquote('"abc"'); diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 65c2f65920e..cc25a703575 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -1964,11 +1964,10 @@ String *Item_func_json_search::val_str(String *str) goto error; c_path->parsed= c_path->constant; } + if (args[n_arg]->null_value) + goto null_return; } - if (args[n_arg]->null_value) - goto null_return; - json_scan_start(&je, js->charset(),(const uchar *) js->ptr(), (const uchar *) js->ptr() + js->length()); @@ -2063,6 +2062,7 @@ end: goto error; } + null_value= 0; return str;