Skip to content

Commit 8abdcba

Browse files
MDEV-37082: Sig 11 in json_normalize_sort
Analysis: json_valid() does not call any function recursively so insertion in the table works ok. Since the depth of json is 5000, json_normalize() recursively calls json_normalize_sort(), json_norm_to_string() and json_norm_value_free() and we hit the stack limit. Fix: Get rid of the recursive nature of the functions and make them iterative. This way we will never hit stack limit for bigger depths.
1 parent a0bdb3b commit 8abdcba

File tree

3 files changed

+384
-152
lines changed

3 files changed

+384
-152
lines changed

mysql-test/main/mdev_32854.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,14 @@ SELECT JSON_VALUE(@json_doc_arr_lev45_valid, '$[1][1][1][1][1][1][1][1][1][1][1]
452452
JSON_VALUE(@json_doc_arr_lev45_valid, '$[1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1]')
453453
45
454454
DROP TABLE t1 ,t2;
455+
#
456+
# MDEV-37082: Sig 11 in json_normalize_sort
457+
#
458+
CREATE TABLE t (a JSON)Engine=InnoDB;
459+
INSERT INTO t VALUES (CONCAT (REPEAT('{"v":',5000),'1',REPEAT('}',5000)));
460+
INSERT INTO t VALUES (CONCAT (REPEAT('[',5000),'1',REPEAT(']',5000)));
461+
SELECT JSON_EQUALS (a,a) FROM t;
462+
JSON_EQUALS (a,a)
463+
1
464+
1
465+
DROP TABLE t;

mysql-test/main/mdev_32854.test

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ SELECT JSON_SCHEMA_VALID(@json_schema, @json_doc_obj_lev45_valid) AS found_path;
9090
SELECT JSON_SCHEMA_VALID(@json_schema, @json_doc_obj_lev45_valid2);
9191

9292

93-
9493
SELECT JSON_SEARCH(@json_doc_obj_lev45_valid,'one', 'This is level 45');
9594

9695
SET @json_updated = JSON_SET(@json_doc_obj_lev45_valid,
@@ -111,3 +110,18 @@ SELECT JSON_VALUE(@json_doc_obj_lev45_valid, '$.level1.level2.level3.level4.leve
111110
SELECT JSON_VALUE(@json_doc_arr_lev45_valid, '$[1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1][1]');
112111

113112
DROP TABLE t1 ,t2;
113+
114+
--echo #
115+
--echo # MDEV-37082: Sig 11 in json_normalize_sort
116+
--echo #
117+
118+
--source include/have_innodb.inc
119+
120+
CREATE TABLE t (a JSON)Engine=InnoDB;
121+
122+
INSERT INTO t VALUES (CONCAT (REPEAT('{"v":',5000),'1',REPEAT('}',5000)));
123+
INSERT INTO t VALUES (CONCAT (REPEAT('[',5000),'1',REPEAT(']',5000)));
124+
125+
SELECT JSON_EQUALS (a,a) FROM t;
126+
127+
DROP TABLE t;

0 commit comments

Comments
 (0)