mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
MDEV-22011: DISTINCT with JSON_ARRAYAGG gives wrong results
For DISTINCT to be handled with JSON_ARRAYAGG, we need to make sure that the Unique tree also holds the NULL bytes of a table record inside the node of the tree. This behaviour for JSON_ARRAYAGG is different from GROUP_CONCAT because in GROUP_CONCAT we just reject NULL values for columns. Also introduced a comparator function for the unique tree to handle null values for distinct inside JSON_ARRAYAGG.
This commit is contained in:
@ -763,6 +763,37 @@ select json_arrayagg(a order by a asc) from (select 1 a union select 2 a) t;
|
||||
|
||||
select json_object('x', json_arrayagg(json_object('a', 1)));
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-22011: DISTINCT with JSON_ARRAYAGG gives wrong results
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1(a INT, b INT);
|
||||
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
|
||||
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
|
||||
|
||||
SELECT JSON_ARRAYAGG(a) FROM t1;
|
||||
SELECT JSON_ARRAYAGG(DISTINCT a) FROM t1;
|
||||
|
||||
INSERT INTO t1 VALUES (NULL,NULL), (NULL,NULL);
|
||||
|
||||
SELECT JSON_ARRAYAGG(a) FROM t1;
|
||||
SELECT JSON_ARRAYAGG(DISTINCT a) FROM t1;
|
||||
DROP TABLE t1;
|
||||
|
||||
CREATE TABLE t1(a VARCHAR(10), b INT);
|
||||
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
|
||||
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
|
||||
|
||||
SELECT JSON_ARRAYAGG(a) FROM t1;
|
||||
SELECT JSON_ARRAYAGG(DISTINCT a) FROM t1;
|
||||
|
||||
INSERT INTO t1 VALUES (NULL,NULL), (NULL,NULL);
|
||||
|
||||
SELECT JSON_ARRAYAGG(a) FROM t1;
|
||||
SELECT JSON_ARRAYAGG(DISTINCT a) FROM t1;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo #
|
||||
--echo # End of 10.5 tests
|
||||
--echo #
|
||||
|
Reference in New Issue
Block a user