Bug #101048 The result is inconsistent between join and group by
Submitted: 4 Oct 2020 1:38 Modified: 20 Dec 2023 19:26
Reporter: zetao wei Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: JSON Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[4 Oct 2020 1:38] zetao wei
Description:
Examples of json:
{ "t" : -999}
{ "t" : -999.0}

The value of '$.t':
Is considered to be the same value by `GroupBY`.
Is considered to be different value by `JOIN`.

The same value is in different operators, and the results are inconsistent.

How to repeat:
CREATE TABLE t1(id INT PRIMARY KEY AUTO_INCREMENT, j JSON);
insert into t1(j) values 
('{ "t" : -999}'), 
('{ "t" : -999.0}');

CREATE TABLE t2(id INT PRIMARY KEY AUTO_INCREMENT, j JSON);
insert into t2(j) values 
('{ "t" : -999.0}');

mysql> select j->'$.t' from t1 group by 1;
+----------+
| j->'$.t' |
+----------+
| -999     |
+----------+

mysql> select * from t1,t2 where t1.j->'$.t' = t2.j->'$.t';
+----+---------------+----+---------------+
| id | j             | id | j             |
+----+---------------+----+---------------+
|  2 | {"t": -999.0} |  1 | {"t": -999.0} |
+----+---------------+----+---------------+

Suggested fix:
Whether integer and floating-point types do forced type conversion is expected to keep consistent behavior in different operators.
[4 Oct 2020 13:30] MySQL Verification Team
Thank you for the bug report.
[15 Apr 2021 13:06] Tor Didriksen
Posted by developer:
 
We join strings, and create hash values for "-999" and "-999.0".
[20 Dec 2023 19:26] Jon Stephens
Documented fix as follows in the MySQL 8.3.0 changelog:

    JOIN and GROUP BY handled JSON column values differently.

Closed.
[17 Jan 18:21] Jean-François Gagné
This is flagged as fixed in 8.3.0, but also as affecting 8.0.

Will this be fixed in a future 8.0 release.
[27 Feb 13:51] Jon Stephens
Also fixed in MySQL 8.0.37 and 8.4.0.

Changelog entry as above.