Skip to content
/ server Public

Comments

MDEV-38873 json_extract returns NULL through derived table#4680

Draft
varundeepsaini wants to merge 1 commit intoMariaDB:mainfrom
varundeepsaini:MDEV-38873-json-extract-derived-table
Draft

MDEV-38873 json_extract returns NULL through derived table#4680
varundeepsaini wants to merge 1 commit intoMariaDB:mainfrom
varundeepsaini:MDEV-38873-json-extract-derived-table

Conversation

@varundeepsaini
Copy link
Contributor

  • The Jira issue number for this PR is: MDEV-38873

Description

json_extract() passes its result through json_nice() with LOOSE format, which expands the output by adding spaces after commas and colons (e.g. ["a",1]["a", 1]). The max_length in Item_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 outer json_extract() to fail with "Unexpected end of JSON text".

Fixed by multiplying max_length by 2 to account for the LOOSE format expansion, matching JSON_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?

./mysql-test/mtr --suite=main func_json

Basing the PR against the correct MariaDB version

  • This is a new feature and the PR is based against the main branch.
  • This is a bug fix.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

json_extract() passes its result through json_nice() with LOOSE
format, which can expand the output by adding spaces after commas
and colons. The max_length was not accounting for this expansion,
causing derived tables to truncate the result and the outer
json_extract() to fail with "Unexpected end of JSON text".

Fix by multiplying max_length by 2 to match JSON_FORMAT(LOOSE).

Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
@varundeepsaini varundeepsaini force-pushed the MDEV-38873-json-extract-derived-table branch from 95b0d9b to 8653482 Compare February 22, 2026 15:21
@varundeepsaini varundeepsaini marked this pull request as draft February 22, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant