Skip to content

Conversation

@yuji-hatakeyama
Copy link

@yuji-hatakeyama yuji-hatakeyama commented Jan 19, 2026

Summary

Fixes #5306

When SHOW WARNINGS queries contain inline comments (e.g., SHOW /* comment */ WARNINGS),
ProxySQL incorrectly returns warning_count

This PR fixes the issue by using digest_text (which has comments stripped) instead of raw query text for SHOW WARNINGS detection,
following the existing pattern used in update_warning_count_from_connection().

Changes

  • lib/mysql_connection.cpp: Use digest_text to detect SHOW WARNINGS for add_eof() call
  • test/tap/tests/reg_test_5306-show_warnings_with_comment-t.cpp: Add regression test
  • test/tap/groups/groups.json: Register new test

Test

The regression test verifies that both SHOW WARNINGS and SHOW /* comment */ WARNINGS return
warning_count=0 in the EOF packet after a query that produces warnings.

The test is excluded from mysql-query_digests=0 and mysql-query_digests_keep_comment=1 groups,
because digest_text is unavailable or contains comments in these configurations.
a609bc9

This is consistent with other digest_text-based detection logic in the codebase (e.g., update_warning_count_from_connection()).

Summary by CodeRabbit

  • Bug Fixes

    • Fixed EOF handling for SHOW WARNINGS in asynchronous query mode so warning counts are reported correctly when queries include inline comments.
  • Tests

    • Added a regression test verifying SHOW WARNINGS returns consistent warning_count in EOF packets for queries with and without inline comments.

✏️ Tip: You can customize this high-level summary in your review settings.

@gemini-code-assist
Copy link

Summary of Changes

Hello @yuji-hatakeyama, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a bug in ProxySQL where SHOW WARNINGS queries containing inline comments would lead to an incorrect warning_count being returned. The fix involves updating the query parsing logic to use the 'digested' form of the query, which is free of comments, thereby standardizing how SHOW WARNINGS is identified. This ensures that the warning_count is accurately reported, improving the reliability of warning handling within the system. A new test case has been introduced to validate this corrected behavior.

Highlights

  • Fix for SHOW WARNINGS with inline comments: Resolved an issue where ProxySQL incorrectly reported warning_count when SHOW WARNINGS queries included inline comments (e.g., SHOW /* comment */ WARNINGS).
  • Improved query detection logic: The detection mechanism for SHOW WARNINGS now utilizes digest_text, which automatically strips comments, ensuring consistent behavior regardless of comment presence in the query.
  • New regression test: A dedicated regression test (reg_test_5306-show_warnings_with_comment-t.cpp) has been added to verify that both commented and uncommented SHOW WARNINGS queries correctly return warning_count=0 in the EOF packet after a query that produces warnings.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Jan 19, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Replaces raw-query comparison with digest_text-based detection for SHOW WARNINGS EOF handling in the async result path; adds a TAP regression test verifying SHOW WARNINGS with inline comments yields correct EOF warning_count.

Changes

Cohort / File(s) Summary
EOF handling fix for SHOW WARNINGS
lib/mysql_connection.cpp
Use digest_text (comments stripped, case-insensitive) instead of raw query text/length to detect SHOW WARNINGS when deciding to call add_eof(true) in the ASYNC_USE_RESULT_CONT path.
Regression test added
test/tap/groups/groups.json, test/tap/tests/reg_test_5306-show_warnings_with_comment-t.cpp
Add new test group entry and TAP test that induces a warning and asserts SHOW WARNINGS (with and without inline comments) yields EOF packets with warning_count = 0.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I sniffed the bytes where comments hide,
Dug up the digest, set logic right inside.
No noisy warnings in EOF's light,
I hopped, I fixed, and tucked them tight. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: fixing SHOW WARNINGS detection by handling inline comments, which is the primary objective addressed in the PR.
Linked Issues check ✅ Passed The PR successfully addresses issue #5306 by modifying SHOW WARNINGS detection to use digest_text instead of raw query text, properly handling inline comments as requested.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the SHOW WARNINGS detection issue. The code modification in mysql_connection.cpp, test file, and test registration are all necessary and in-scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

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

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 correctly fixes a bug where SHOW WARNINGS with inline comments would not be detected properly, leading to an incorrect warning_count. The approach of using digest_text is sound and consistent with other parts of the codebase. The added regression test is thorough and covers the necessary cases.

I've added a couple of suggestions: one to improve the performance of the string comparison in mysql_connection.cpp and another to clean up unused headers in the new test file. Overall, this is a good fix.

Comment on lines +1831 to +1832
const size_t dig_len = strlen(dig_text);
is_show_warnings = (dig_len == 13 && strncasecmp(dig_text, "SHOW WARNINGS", 13) == 0);

Choose a reason for hiding this comment

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

medium

To improve efficiency, you can avoid calling strlen, which scans the entire string. A more performant approach for an exact match check is to use strncasecmp and then verify the string ends with a null terminator right after the matched part.

is_show_warnings = (strncasecmp(dig_text, "SHOW WARNINGS", 13) == 0 && dig_text[13] == '\0');

Copy link
Author

Choose a reason for hiding this comment

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

Keeping the current style for consistency with the rest of the codebase

e.g.,

(dig_len == 13 && strncasecmp(dig, "SHOW WARNINGS", 13) == 0))) {

Comment on lines 7 to 9
#include <unistd.h>
#include <string>
#include <thread>

Choose a reason for hiding this comment

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

medium

These headers (unistd.h, string, thread) don't appear to be used in this file. It's good practice to remove unused includes to improve compilation times and reduce code clutter.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in 0124c55 .

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@test/tap/tests/reg_test_5306-show_warnings_with_comment-t.cpp`:
- Around line 27-31: The check for proxysql_admin after calling mysql_init()
calls mysql_error(proxysql_admin) while proxysql_admin may be NULL; change the
error path in the mysql_init() failure branch (the proxysql_admin variable) to
avoid calling mysql_error with a NULL handle and instead log a static
descriptive message (e.g. "mysql_init() failed") or include errno-based text;
update the fprintf call in that block to use the static message rather than
mysql_error(proxysql_admin).
- Around line 42-51: The early-return error paths leak MySQL handles: ensure any
MYSQL* that was successfully initialized/connected is closed before returning.
Specifically, if mysql_real_connect(proxysql, ...) fails call
mysql_close(proxysql) (and similarly call mysql_close(proxysql_admin) on paths
where proxysql_admin was created but you return early); update the error
branches that use mysql_error(proxysql) to close the corresponding MYSQL*
handles before returning or calling exit_status().

Comment on lines +42 to +51
MYSQL* proxysql = mysql_init(NULL);
if (!proxysql) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql));
return -1;
}

if (!mysql_real_connect(proxysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql));
return exit_status();
}
Copy link

@coderabbitai coderabbitai bot Jan 19, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Minor: Resource leak on early return.

If the ProxySQL connection fails, proxysql_admin is not closed before returning. Similar pattern appears for the proxysql_admin initialization failure at line 29 (though less critical since nothing was allocated yet for other resources).

Proposed fix
 	MYSQL* proxysql = mysql_init(NULL);
 	if (!proxysql) {
 		fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql));
+		mysql_close(proxysql_admin);
 		return -1;
 	}
 
 	if (!mysql_real_connect(proxysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
 		fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql));
+		mysql_close(proxysql);
+		mysql_close(proxysql_admin);
 		return exit_status();
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
MYSQL* proxysql = mysql_init(NULL);
if (!proxysql) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql));
return -1;
}
if (!mysql_real_connect(proxysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql));
return exit_status();
}
MYSQL* proxysql = mysql_init(NULL);
if (!proxysql) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql));
mysql_close(proxysql_admin);
return -1;
}
if (!mysql_real_connect(proxysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql));
mysql_close(proxysql);
mysql_close(proxysql_admin);
return exit_status();
}
🤖 Prompt for AI Agents
In `@test/tap/tests/reg_test_5306-show_warnings_with_comment-t.cpp` around lines
42 - 51, The early-return error paths leak MySQL handles: ensure any MYSQL* that
was successfully initialized/connected is closed before returning. Specifically,
if mysql_real_connect(proxysql, ...) fails call mysql_close(proxysql) (and
similarly call mysql_close(proxysql_admin) on paths where proxysql_admin was
created but you return early); update the error branches that use
mysql_error(proxysql) to close the corresponding MYSQL* handles before returning
or calling exit_status().

Copy link
Author

Choose a reason for hiding this comment

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

Same pattern in other tests
(e.g.,

fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql));
return -1;
}
// Connect to ProxySQL
if (!mysql_real_connect(proxysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql));
return exit_status();
) .

Since these are test files and resources are freed on process exit anyway. if worth fixing, perhaps better addressed in a separate PR.

Copy link

Choose a reason for hiding this comment

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

@yuji-hatakeyama, you're absolutely right—this is a common pattern in ProxySQL test files, and since these processes are short-lived, the OS will clean up the resources on exit anyway. I agree it's out of scope for this PR and would be better addressed separately if at all. Thanks for the clarification!


✏️ Learnings added
Learnt from: yuji-hatakeyama
Repo: sysown/proxysql PR: 5307
File: test/tap/tests/reg_test_5306-show_warnings_with_comment-t.cpp:39-48
Timestamp: 2026-01-20T09:34:19.124Z
Learning: In ProxySQL test files (test/tap/tests/), resource leaks (such as not calling `mysql_close()` on early return paths) are not typically fixed because test processes are short-lived and the OS frees resources on process exit. This is a common pattern across the test suite.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: yuji-hatakeyama
Repo: sysown/proxysql PR: 5307
File: test/tap/tests/reg_test_5306-show_warnings_with_comment-t.cpp:24-28
Timestamp: 2026-01-20T07:40:27.573Z
Learning: In ProxySQL test files, calling `mysql_error(NULL)` after `mysql_init()` failure is safe because the MariaDB client library implementation returns an empty string for NULL handles (not undefined behavior).

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@test/tap/tests/reg_test_5306-show_warnings_with_comment-t.cpp`:
- Around line 67-70: The test calls mysql_store_result(proxysql) into res and
then unconditionally calls mysql_num_rows(res); add a NULL check for res after
mysql_store_result to avoid undefined behavior: if res is NULL, handle the error
path (e.g., set row_count = 0 or fail the test/assert accordingly) before
calling mysql_num_rows and ensure mysql_free_result is only called when res is
non-NULL. Update the block around MYSQL_QUERY(proxysql, show_query),
mysql_store_result(proxysql), mysql_num_rows(res), and mysql_free_result(res) to
perform this check using the existing variables res, proxysql, show_query and
preserve intent of the test.
♻️ Duplicate comments (3)
test/tap/tests/reg_test_5306-show_warnings_with_comment-t.cpp (3)

25-27: Minor: mysql_error() on potentially NULL handle.

If mysql_init() returns NULL, calling mysql_error(proxysql_admin) is undefined behavior. Use a static error message instead.


39-48: Minor: Resource leaks and mysql_error() on NULL handle.

The issues in this section (calling mysql_error(proxysql) when proxysql may be NULL, and not closing proxysql_admin on failure paths) were flagged in a previous review.


30-33: Minor: Resource leak on admin connection failure.

If mysql_real_connect fails, proxysql_admin was successfully initialized but is not closed before returning.

Proposed fix
 	if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) {
 		fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
+		mysql_close(proxysql_admin);
 		return -1;
 	}

@sonarqubecloud
Copy link

@yuji-hatakeyama
Copy link
Author

All bot feedback has been addressed. Ready for review when you have a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SHOW WARNINGS with inline comments incorrectly sets warning_count

1 participant