Bug #120110 Wrong result: DISTINCT eliminates JSON_OBJECT result containing NULL value
| Submitted: | 19 Mar 9:04 | Modified: | 19 Mar 14:06 |
|---|---|---|---|
| Reporter: | Wang Ojiken | Email Updates: | |
| Status: | Verified | Impact on me: | |
| Category: | MySQL Server: JSON | Severity: | S3 (Non-critical) |
| Version: | 8.0.45 | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
| Tags: | distinct, json, JSON_OBJECT, null, wrong result | ||
[19 Mar 14:06]
Roy Lyseng
Thank you for the bug report. Verified as described.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.053 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: When applying DISTINCT to results produced by JSON_OBJECT, MySQL incorrectly removes rows that contain JSON null values. Specifically, JSON_OBJECT('k', NULL) produces a valid JSON value {"k": null}, which is semantically distinct from {"k": 0} and {"k": 1}. However, when DISTINCT is applied, the row corresponding to {"k": null} is missing from the result. This indicates that MySQL either treats JSON null as SQL NULL or incorrectly compares JSON values during DISTINCT evaluation, leading to loss of semantically distinct results. How to repeat: DROP TABLE IF EXISTS t1; CREATE TABLE t1 ( c0 DECIMAL NULL ); INSERT INTO t1 (c0) VALUES (0); INSERT INTO t1 (c0) VALUES (1); INSERT INTO t1 (c0) VALUES (NULL); -- Query 1 (with DISTINCT) SELECT DISTINCT JSON_OBJECT('k', t1.c0) FROM t1 GROUP BY t1.c0; -- Query 2 (baseline) SELECT JSON_OBJECT('k', t1.c0) FROM t1 GROUP BY t1.c0; Expected result: Query 1: {"k": 0} {"k": 1} {"k": null} Query 2: {"k": 0} {"k": 1} {"k": null} Actual result: Query 1: {"k": 0} {"k": 1} Query 2: {"k": 0} {"k": 1} {"k": null} Suggested fix: After my testing, I believe there are common issues at the JSON level. I hope these problems can be identified and resolved.