diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index 460ff8fa1d2..cace2f985ac 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -209,6 +209,9 @@ json_extract('[10, 20, [{"a":3}, 30, 40]]', '$[2][*]') select json_extract('1', '$'); json_extract('1', '$') 1 +select json_extract('[10, 20, [30, 40], 1, 10]', '$[1]'); +json_extract('[10, 20, [30, 40], 1, 10]', '$[1]') +20 select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.k1', 'word'); json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.k1', 'word') {"a":1, "b":{"c":1, "k1":"word"}, "d":[1, 2]} diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index 72b7b946536..7e10a4fb203 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -77,6 +77,7 @@ select json_extract(json_object('foo', 'foobar'),'$'); select json_extract('[10, 20, [30, 40]]', '$[2][*]'); select json_extract('[10, 20, [{"a":3}, 30, 40]]', '$[2][*]'); select json_extract('1', '$'); +select json_extract('[10, 20, [30, 40], 1, 10]', '$[1]'); select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.k1', 'word'); select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.d[3]', 3); diff --git a/strings/json_lib.c b/strings/json_lib.c index a93200cd4dd..47a3e37fa4c 100644 --- a/strings/json_lib.c +++ b/strings/json_lib.c @@ -1270,7 +1270,7 @@ int json_find_path(json_engine_t *je, case JST_VALUE: DBUG_ASSERT(cur_step->type & JSON_PATH_ARRAY); if (cur_step->type & JSON_PATH_WILD || - cur_step->n_item == array_counters[cur_step - p->steps]) + cur_step->n_item == array_counters[cur_step - p->steps]++) { /* Array item matches. */ if (cur_step == p->last_step || @@ -1278,10 +1278,7 @@ int json_find_path(json_engine_t *je, goto exit; } else - { json_skip_array_item(je); - array_counters[cur_step - p->steps]++; - } break; case JST_OBJ_END: case JST_ARRAY_END: