MDEV-28922 JSON_NORMALIZE handling of duplicate keys#5289
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds test cases and a fix for handling duplicate keys in JSON_NORMALIZE (MDEV-28922). However, the implementation in strings/json_normalize.c contains a critical bug where it directly accesses the string member of the value union without checking its type, which can lead to undefined behavior, segmentation faults, or non-deterministic sorting. A recursive value comparison helper is recommended to safely compare different JSON types.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Despite the JSON spec rfc8259/#section-4 "The names within an object SHOULD be unique"[1], it does happen. As our sort algorithm has access to both key and value, if the key matches, sort by the value. The type, and length of objects, strings, arrays and numbers is easy, so use those as a first comparision point. [1] https://www.rfc-editor.org/info/rfc8259/#section-4
Despite the JSON spec rfc8259/#section-4
"The names within an object SHOULD be unique"[1], it does happen.
As our sort algorithm has access to both key and value, if the key matches, sort by the value.
[1] https://www.rfc-editor.org/info/rfc8259/#section-4