Skip to content

MDEV-40165 10.11 JSON functions don't respect KILL QUERY#5117

Open
grooverdan wants to merge 3 commits into
MariaDB:10.11from
grooverdan:MDEV-28404
Open

MDEV-40165 10.11 JSON functions don't respect KILL QUERY#5117
grooverdan wants to merge 3 commits into
MariaDB:10.11from
grooverdan:MDEV-28404

Conversation

@grooverdan

@grooverdan grooverdan commented May 24, 2026

Copy link
Copy Markdown
Member

Or max_statement_time limit.

Implement interuptability of:
* JSON_OVERLAPS
* JSON_LENGTH
* JSON_DEPTH

@grooverdan grooverdan added the MariaDB Foundation Pull requests created by MariaDB Foundation label May 24, 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 introduces a mechanism to make JSON processing interruptible by checking a killed_ptr within the JSON engine and returning a new JE_KILLED error code. While the changes integrate this check into several JSON functions and update error reporting, the review identifies a critical risk of NULL pointer dereference in json_scan_next if the pointer is not initialized. Additionally, feedback points out that some functions incorrectly assume they are not interruptible or have lost interruptibility due to the removal of manual check_killed() calls without proper pointer initialization.

Comment thread strings/json_lib.c Outdated
Comment thread sql/item_jsonfunc.cc
Comment thread sql/item_jsonfunc.cc
Comment thread sql/item_jsonfunc.cc
@grooverdan grooverdan force-pushed the MDEV-28404 branch 3 times, most recently from f80774b to 6dee764 Compare May 24, 2026 07:11
@grooverdan

Copy link
Copy Markdown
Member Author

Replaced with 10.6 version - #5045

There's still a need to correct the killabilty of JSON_OVERLAPs and maybe JSON_NORMALIZE in 10.11, so moving to a draft for now.

@grooverdan grooverdan marked this pull request as draft June 3, 2026 04:19
Or max_statement_time limit.

Implement interuptability of:
* JSON_OVERLAPS
* JSON_LENGTH
* JSON_DEPTH

As json_report_error now processes the killed there's
no need of thd->check_killed(). Removed this from a few
locations.

Verified that the path after every json_scan_next, the
location of checking the killed_ptr, reports errors
correctly.
@grooverdan grooverdan changed the title MDEV-28404 JSON functions don't respect KILL QUERY MDEV-40165 10.11 JSON functions don't respect KILL QUERY Jun 26, 2026
@grooverdan grooverdan marked this pull request as ready for review June 26, 2026 09:17
Or max_statement_time limit.

JSON_EQUAL/JSON_NORMALIZE also didn't report warnings
on invalid JSON inputs.

Change the json_normalize function to take a json_engine_t
as a argument and implement the sql/item_jsonfunc.cc calls
to have a json_engine_t.

To the JSON_EQUALS and JSON_NORMALIZE, add error handling
to produce an error when there was one. compare_nested_object,
part of JSON_OVERLAPS, uses a new json_engine and
copies the error/position to the returning function.

json_normalize expects the incoming je structure to have
a valid, or nullptr, killed_ptr, as json_start will reset this.
Or max_statement_time limit.

Change the json_valid to take a json_engine_t argument.
Adjust the Item_json_valid to have a json_engine_t and
to report an error.

Note this means that invalid json syntax now has a
note on any json error. Raising this to a warning can
cause check constraints of JSON_VALID() to result
in ER_JSON_SYNTAX rather than ER_CONSTRAINT_FAILED
(valided in main.type_json test).

Consequential changes in debug build to json acl
testing validation and unit test having a dummy json_engine_t.

json_normalize also uses the same engine that was
passed as its argument to test json_valid. Because
the character set may have changed, if there's an error
adjust the je->s.c_str pointer. Its only the offset that
is currently used in the error messages anyway so there
may be offset errors depending on the original character
set.
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