Skip to content

MDEV-28922 JSON_NORMALIZE handling of duplicate keys#5289

Open
grooverdan wants to merge 1 commit into
MariaDB:10.11from
grooverdan:MDEV-28922
Open

MDEV-28922 JSON_NORMALIZE handling of duplicate keys#5289
grooverdan wants to merge 1 commit into
MariaDB:10.11from
grooverdan:MDEV-28922

Conversation

@grooverdan

Copy link
Copy Markdown
Member

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

@grooverdan grooverdan added the MariaDB Foundation Pull requests created by MariaDB Foundation label Jun 29, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread strings/json_normalize.c
@grooverdan grooverdan marked this pull request as draft June 29, 2026 06:20
@grooverdan grooverdan marked this pull request as ready for review June 29, 2026 07:46
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MariaDB Foundation Pull requests created by MariaDB Foundation

Development

Successfully merging this pull request may close these issues.

2 participants