-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
MDEV-30354 Fix JSON escaping in optimizer trace #4259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
2523483
to
50d1ce0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@y2kwak thanks for your contribution! A few minor issues outlined.
The expanded_query field in optimizer trace could produce invalid JSON when queries contained special characters. Use json_escape() to properly handle quotes, backslashes and other special characters in the output. If json_escape() fails, emit an error message in the expanded_query. Example: Before: "expanded_query": "select length('a') AS `LENGTH("a")`" After: "expanded_query": "select length('a') AS `LENGTH(\"a\")`" The output is now properly escaped and valid JSON while maintaining readability. Added test cases to mysql-test/main/opt_trace.test to verify the fix. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.
Description
Currently, when using optimizer trace, the expanded_query field can produce invalid JSON when queries contain special characters like quotes or backslashes. This makes the JSON output invalid and difficult to parse programmatically.
This PR modifies the expanded_query output to properly escape special characters using json_escape(), ensuring valid JSON output while maintaining readability.
It also includes MTR tests to verify the fix.
How can this PR be tested?
Enable optimizer trace and run queries with special characters:
Before change:
After change:
Additional test cases:
SELECT LENGTH("a\"b");
SELECT LENGTH("a\n\"b\t\"c");
Basing the PR against the correct MariaDB version
Copyright
All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.