[MDEV-32605] JSON_CONTAINS changes the JSON result Created: 2023-10-27  Updated: 2023-11-28

Status: Open
Project: MariaDB Server
Component/s: JSON
Affects Version/s: 10.8.8
Fix Version/s: 10.11, 11.0, 11.1, 11.2

Type: Bug Priority: Major
Reporter: Marco Ripa Assignee: Rucha Deodhar
Resolution: Unresolved Votes: 0
Labels: json
Environment:

Debian 10 - 10.8.8-MariaDB-1:10.8.8+maria~deb10-log - mariadb.org binary distribution



 Description   

JSON_CONTAINS somehow modifies the JSON_ARRAYAGG result, transforming an array to a bidimensional array:

CREATE TABLE temp (v varchar(10), t int);
 
INSERT INTO temp (v,t) VALUES ('A',1);
INSERT INTO temp (v,t) VALUES ('B',1);
INSERT INTO temp (v,t) VALUES ('B',2);
INSERT INTO temp (v,t) VALUES ('C',2);
INSERT INTO temp (v,t) VALUES ('C',3);
 
SELECT JSON_ARRAYAGG(v) as array FROM temp GROUP BY t;

+-----------+
| array     |
+-----------+
| ["A","B"] |
| ["B","C"] |
| ["C"]     |
+-----------+
3 rows in set (0.010 sec)

All perfect, until we try to make a JSON_CONTAINS:

SELECT JSON_ARRAYAGG(v) as array FROM temp GROUP BY t HAVING JSON_CONTAINS(array, JSON_QUOTE('B'),'$');

+-------------+
| array       |
+-------------+
| [["A","B"]] |
| [["B","C"]] |
+-------------+
2 rows in set (0.006 sec)

The array column in the resulting rows is become a bidimensional array.
This doesn't happen on MySQL 8.


Generated at Thu Feb 08 10:32:37 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.