Bug #107199 | Inconsistent JSON path ** behaviour between versions | ||
---|---|---|---|
Submitted: | 3 May 2022 15:33 | Modified: | 12 May 2022 16:48 |
Reporter: | chen chen | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: JSON | Severity: | S3 (Non-critical) |
Version: | 8.0.27 | OS: | Any |
Assigned to: | Jon Stephens | CPU Architecture: | Any |
[3 May 2022 15:33]
chen chen
[4 May 2022 6:37]
MySQL Verification Team
Hello Chen, Thank you for the documentation enhancement request! Thanks, Umesh
[12 May 2022 16:17]
Jon Stephens
Hi Chen, '**' matches any sequence of keys. It is not a wildcard that matches partial key names; the exact key names used as the prefix and the suffix must be present in the JSON in order to be matched. For example, '$.a**.c' matches .a.b.c, .a.bx.c, a.e.g.c., etc but not ax.b.c, .a.b.cx, .a.b.c.d, etc. In the course of testing some examples, I found that MySQL 5.7 and 8.0 give different results for some uses of '**' and that both give unexpected results in some cases, so I'm turning this into a software bug. We'll revisit the issue with the documentation once the software issues have been resolved. Thanks!
[12 May 2022 17:13]
Jon Stephens
5.7.38: mysql> SELECT JSON_EXTRACT('{"abc": {"def": {"ghi": 3, "jkl": 4}}, "abc": {"pqr": {"mno": 7, "jkl": 8}}}', '$.ab**.jkl'); +------------------------------------------------------------------------------------------------------------+ | JSON_EXTRACT('{"abc": {"def": {"ghi": 3, "jkl": 4}}, "abc": {"pqr": {"mno": 7, "jkl": 8}}}', '$.ab**.jkl') | +------------------------------------------------------------------------------------------------------------+ | NULL | +------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> SELECT JSON_EXTRACT('{"abc": {"def": {"ghi": 3, "jkl": 4}}, "abc": {"pqr": {"mno": 7, "jkl": 8}}}', '$.abc**.jkl'); +-------------------------------------------------------------------------------------------------------------+ | JSON_EXTRACT('{"abc": {"def": {"ghi": 3, "jkl": 4}}, "abc": {"pqr": {"mno": 7, "jkl": 8}}}', '$.abc**.jkl') | +-------------------------------------------------------------------------------------------------------------+ | [4] | +-------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) +-------------------------------------------------------------------------------------------+ 8.0.30: mysql> SELECT JSON_EXTRACT('{"abc": {"def": {"ghi": 3, "jkl": 4}}, "abc": {"pqr": {"mno": 7, "jkl": 8}}}', '$.ab**.jkl'); +------------------------------------------------------------------------------------------------------------+ | JSON_EXTRACT('{"abc": {"def": {"ghi": 3, "jkl": 4}}, "abc": {"pqr": {"mno": 7, "jkl": 8}}}', '$.ab**.jkl') | +------------------------------------------------------------------------------------------------------------+ | NULL | +------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> SELECT JSON_EXTRACT('{"abc": {"def": {"ghi": 3, "jkl": 4}}, "abc": {"pqr": {"mno": 7, "jkl": 8}}}', '$.abc**.jkl'); +-------------------------------------------------------------------------------------------------------------+ | JSON_EXTRACT('{"abc": {"def": {"ghi": 3, "jkl": 4}}, "abc": {"pqr": {"mno": 7, "jkl": 8}}}', '$.abc**.jkl') | +-------------------------------------------------------------------------------------------------------------+ | [8] | +-------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
[12 May 2022 19:40]
Jon Stephens
The result of the first query is correct--MySQL thinks you're looking for a match on a path beginning with a key named 'ab' which does not match any of the keys in the document. But shouldn't this JSON_EXTRACT('{"abc": {"def": {"ghi": 3, "jkl": 4}}, "abc": {"pqr": {"mno": 7, "jkl": 8}}}', '$.abc**.jkl') return this [4, 8] in both cases? It also seems odd that 5.7 matches only the one, yet 8.0 matches only the other. Thanks!