From ce55094f4fee3c0ff2c58ac4dd3ef2c16c5e20c3 Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Fri, 16 Dec 2016 14:06:12 +0400 Subject: [PATCH] MDEV-11572 JSON_DEPTH returns wrong results. JSON depth calculation fixed. --- mysql-test/r/func_json.result | 3 +++ mysql-test/t/func_json.test | 1 + sql/item_jsonfunc.cc | 1 + 3 files changed, 5 insertions(+) diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index 8ce3ccb876f..a704274a112 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -405,6 +405,9 @@ json_depth('[[], {}]') select json_depth('[[[1,2,3],"s"], {}, []]'); json_depth('[[[1,2,3],"s"], {}, []]') 4 +select json_depth('[10, {"a": 20}]'); +json_depth('[10, {"a": 20}]') +3 select json_length(''); json_length('') NULL diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index b85b89c068d..a1d3d819adf 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -163,6 +163,7 @@ select cast(NULL AS JSON); select json_depth(cast(NULL as JSON)); select json_depth('[[], {}]'); select json_depth('[[[1,2,3],"s"], {}, []]'); +select json_depth('[10, {"a": 20}]'); select json_length(''); select json_length('{}'); diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 413b241f496..42570984e8d 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -1624,6 +1624,7 @@ longlong Item_func_json_depth::val_int() switch (je.state) { case JST_VALUE: + case JST_KEY: if (inc_depth) { c_depth++;