[MDEV-22685] View returns a wrong result set if its definition contains JSON_ARRAYAGG Created: 2020-05-24  Updated: 2020-06-04  Resolved: 2020-06-04

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: None
Fix Version/s: 10.5.4

Type: Bug Priority: Critical
Reporter: Igor Babaev Assignee: Alexey Botchkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Problem/Incident

 Description   

Create and populate table t1 with commands:

create table t1 (o_id int, attribute varchar(16), value varchar(16));
insert into t1 values (2,'color','red'),(2,'fabric','silk'),(3,'color','green'),(3,'shape','square');

Define view v1:

create view v1 as SELECT o_id, JSON_ARRAYAGG(attribute) AS attributes FROM t1 GROUP BY o_id order by attribute;

The query

select * from v1;

returns

MariaDB [test]> select * from v1;
+------+--------------+
| o_id | attributes   |
+------+--------------+
|    2 | color,fabric |
|    3 | color,shape  |
+------+--------------+

while the query used in the definition of v1 returns

MariaDB [test]> SELECT o_id, JSON_ARRAYAGG(attribute) AS attributes FROM t1 GROUP BY o_id order by attribute;
+------+--------------------+
| o_id | attributes         |
+------+--------------------+
|    2 | ["color","fabric"] |
|    3 | ["color","shape"]  |
+------+--------------------+

We also have:

MariaDB [test]> show create view v1;
+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| View | Create View                                                                                                                                                                                                                | character_set_client | collation_connection |
+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| v1   | CREATE ALGORITHM=UNDEFINED DEFINER=`` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`o_id` AS `o_id`,group_concat(`t1`.`attribute` separator ',') AS `attributes` from `t1` group by `t1`.`o_id` order by `t1`.`attribute` | utf8                 | utf8_general_ci      |
+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+

The bug happens because the class Item_func_json_arrayagg lacks an implementation of the print method.



 Comments   
Comment by Alexey Botchkov [ 2020-06-04 ]

https://github.com/MariaDB/server/commit/07daf735422403d2336df65ccc3f808d76b28497

Generated at Thu Feb 08 09:16:40 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.