1
0
mirror of https://github.com/MariaDB/server.git synced 2025-11-09 11:41:36 +03:00

MDEV-36809: json_array_intersect crashs when unused table ref provided

Analysis:
So, there were two problems that needed to be fixed.
1) To fix the crash.
2) After fixing the crash, the result was wrong.
Reason for crash: When we pass the hash to get_intersect_between_arrays(),
We were initialially not passing it value, so the operations were not
performed correctly.
Reason for wrong result: The number of rows that it was returning were same
as that in the table, but, only the first row had correct ouput, rest of
them were NULL (it should also be the result of interection). This was
because we modified the "items" HASH by deleting the "seen" elements.
So for next rows, it did not have the elements it should have in the hash.

Fix:
1) To fix the crash: pass the HASH by reference
2) To fix incorrect result: Maintain a separate "seen" hash, if an item
is found the the "items" hash, delete it ony temporarily and put it in the
seen hash. At then end, put the items from "seen" back into "items" and
reset "seen".
This commit is contained in:
Rucha Deodhar
2025-09-25 01:10:14 +05:30
committed by Daniel Black
parent 44dc149c78
commit 6c56c92a6c
4 changed files with 67 additions and 20 deletions

View File

@@ -5272,6 +5272,8 @@ SET @obj1='{ "a": 1,"b": 2,"c": 3}';
SELECT JSON_OBJECT_FILTER_KEYS (@obj1,@arr1);
JSON_OBJECT_FILTER_KEYS (@obj1,@arr1)
NULL
SET character_set_database=default;
SET CHARACTER SET default;
# End of 11.2 Test
# Beginning of 11.4 Test
#
@@ -5283,4 +5285,16 @@ NULL
SELECT json_array_intersect(@a,@b);
json_array_intersect(@a,@b)
NULL
# MDEV-36809: json_array_intersect crashs when unused table ref provided
#
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;
result
[["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]]
[["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]]
[["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]]
[["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]]
[["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]]
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 ) );
( 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 ) )
1.000000
# End of 11.4 Test