MDEV-38873 json_extract returns NULL through derived table#4680
Open
varundeepsaini wants to merge 1 commit intoMariaDB:10.11from
Open
MDEV-38873 json_extract returns NULL through derived table#4680varundeepsaini wants to merge 1 commit intoMariaDB:10.11from
varundeepsaini wants to merge 1 commit intoMariaDB:10.11from
Conversation
95b0d9b to
8653482
Compare
6267e55 to
8500024
Compare
gkodinov
requested changes
Feb 23, 2026
Member
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for your contribution.
This is a preliminary review.
8500024 to
6720fd8
Compare
6720fd8 to
fe97d5b
Compare
gkodinov
reviewed
Feb 26, 2026
Member
gkodinov
left a comment
There was a problem hiding this comment.
10.11 is the correct target at this point. Please rebase to that.
fe97d5b to
318c6c2
Compare
318c6c2 to
4e46538
Compare
Item_func_json_extract::fix_length_and_dec() underestimated max_length. The result is passed through json_nice() with LOOSE formatting which expands separators (e.g. ["a",1] -> ["a", 1]), but max_length was computed from the input size alone. When the result flows through a materialized derived table, the field is created with this too-small max_length and the output gets truncated. Fix: multiply by 2 to account for LOOSE expansion, add array framing overhead for multi-path extractions, and use fix_char_length_ulonglong() for proper character-to-byte conversion and overflow handling. Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
4e46538 to
1a9425e
Compare
gkodinov
approved these changes
Feb 27, 2026
Member
gkodinov
left a comment
There was a problem hiding this comment.
LGTM. Please stand by for the final review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
json_extract()passes its result throughjson_nice()with LOOSE format, which expands the output by adding spaces after commas and colons (e.g.["a",1]→["a", 1]). Themax_lengthinItem_func_json_extract::fix_length_and_dec()was not accounting for this expansion. When the result passed through a derived table, the field was created with the underestimated length, truncating the JSON string and causing the outerjson_extract()to fail with "Unexpected end of JSON text".Fixed by multiplying
max_lengthby 2 to account for the LOOSE format expansion, matchingJSON_FORMAT(LOOSE)behavior.Release Notes
JSON_EXTRACT()no longer returns NULL with "Unexpected end of JSON text" when its result is used through a derived table.How can this PR be tested?
Basing the PR against the correct MariaDB version
mainbranch.PR quality check