Skip to content

Commit cd28452

Browse files
MDEV-37864: mysql-test/mtr --cursor main.func_json fails
Analysis: Maximum length of the field of the temorary table that cursor protocol uses is not enough, which it actually gets when we prepare the json_array_intersect() function and set the max length of the result. So even though the entire result is sent, only partial is actually copied because the field length is not enough. Fix: Have enough max_length.
1 parent 029d6a0 commit cd28452

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

mysql-test/main/func_json.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5297,4 +5297,14 @@ result
52975297
SELECT ( WITH x AS ( WITH x ( x ) AS ( SELECT ( 1.000000 ) ) SELECT x FROM x ) SELECT * FROM x WHERE ( SELECT AVG ( x ) OVER ( ORDER BY JSON_ARRAY_INTERSECT ( '[["1", "7"], ["2", "6"], ["3", "8"]]' , '[["2","6"],["3","8"],["4","5"],["1","7"]]' ) ) FROM x ) );
52985298
( WITH x AS ( WITH x ( x ) AS ( SELECT ( 1.000000 ) ) SELECT x FROM x ) SELECT * FROM x WHERE ( SELECT AVG ( x ) OVER ( ORDER BY JSON_ARRAY_INTERSECT ( '[["1", "7"], ["2", "6"], ["3", "8"]]' , '[["2","6"],["3","8"],["4","5"],["1","7"]]' ) ) FROM x ) )
52995299
1.000000
5300+
#
5301+
# MDEV-37864: mysql-test/mtr --cursor main.func_json fails
5302+
#
5303+
select json_array_intersect('[["1", "7"], ["2", "6"], ["4", "5"], ["3", "8"]]', '[["2","6"],["3","8"],["4","5"],["1","7"]]') from mysql.user;
5304+
json_array_intersect('[["1", "7"], ["2", "6"], ["4", "5"], ["3", "8"]]', '[["2","6"],["3","8"],["4","5"],["1","7"]]')
5305+
[["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]]
5306+
[["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]]
5307+
[["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]]
5308+
[["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]]
5309+
[["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]]
53005310
# End of 11.4 Test

mysql-test/main/func_json.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4196,4 +4196,10 @@ SELECT json_array_intersect(@a,@b);
41964196
select json_array_intersect('[["1", "7"], ["2", "6"], ["4", "5"], ["3", "8"]]', '[["2","6"],["3","8"],["4","5"],["1","7"]]') as result from mysql.user;
41974197
SELECT ( WITH x AS ( WITH x ( x ) AS ( SELECT ( 1.000000 ) ) SELECT x FROM x ) SELECT * FROM x WHERE ( SELECT AVG ( x ) OVER ( ORDER BY JSON_ARRAY_INTERSECT ( '[["1", "7"], ["2", "6"], ["3", "8"]]' , '[["2","6"],["3","8"],["4","5"],["1","7"]]' ) ) FROM x ) );
41984198

4199+
--echo #
4200+
--echo # MDEV-37864: mysql-test/mtr --cursor main.func_json fails
4201+
--echo #
4202+
4203+
select json_array_intersect('[["1", "7"], ["2", "6"], ["4", "5"], ["3", "8"]]', '[["2","6"],["3","8"],["4","5"],["1","7"]]') from mysql.user;
4204+
41994205
--echo # End of 11.4 Test

sql/item_jsonfunc.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5501,8 +5501,8 @@ bool Item_func_json_array_intersect::prepare_json_and_create_hash(json_engine_t
55015501
null_value= 1;
55025502
}
55035503

5504-
max_length= (args[0]->max_length < args[1]->max_length) ?
5505-
args[0]->max_length : args[1]->max_length;
5504+
max_length= 2*(args[0]->max_length < args[1]->max_length ?
5505+
args[0]->max_length : args[1]->max_length);
55065506

55075507
return false;
55085508
}

0 commit comments

Comments
 (0)