-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #5306 - SHOW WARNINGS with inline comments incorrectly sets warning_count #5307
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: v3.0
Are you sure you want to change the base?
Changes from 2 commits
ea01a83
0975819
a609bc9
0124c55
28037bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,89 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @file reg_test_5306-show_warnings_with_comment-t.cpp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @brief This test verifies that SHOW WARNINGS with inline comments does not incorrectly return warning_count in EOF packet. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <stdio.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <unistd.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <string> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <thread> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "mysql.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "mysqld_error.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "tap.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "command_line.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "utils.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int main(int argc, char** argv) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CommandLine cl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (cl.getEnv()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| diag("Failed to get the required environmental variables."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| plan(4); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Initialize Admin connection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MYSQL* proxysql_admin = mysql_init(NULL); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!proxysql_admin) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Connnect to ProxySQL Admin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MYSQL_QUERY(proxysql_admin, "SET mysql-handle_warnings=1"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Initialize ProxySQL connection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+39
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: Resource leak on early return. If the ProxySQL connection fails, 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
Suggested change
🤖 Prompt for AI Agents
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same pattern in other tests proxysql/test/tap/tests/reg_test_4072-show-warnings-t.cpp Lines 44 to 51 in 2637d28
Since these are test files and resources are freed on process exit anyway. if worth fixing, perhaps better addressed in a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
✏️ Learnings added
🧠 Learnings used |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Query that produces a warning (truncation warning) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const char* WARNING_QUERY = "SELECT CAST('abc' AS DOUBLE)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Test cases: SHOW WARNINGS without and with comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const char* show_warnings_queries[] = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "SHOW WARNINGS", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "SHOW /* comment */ WARNINGS" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const char* show_query : show_warnings_queries) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MYSQL_QUERY(proxysql, WARNING_QUERY); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MYSQL_RES* res = mysql_store_result(proxysql); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mysql_free_result(res); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unsigned int warning_count_after_query = mysql_warning_count(proxysql); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| diag("After WARNING_QUERY: warning_count=%u", warning_count_after_query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MYSQL_QUERY(proxysql, show_query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| res = mysql_store_result(proxysql); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unsigned int row_count = mysql_num_rows(res); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mysql_free_result(res); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unsigned int warning_count_after_show = mysql_warning_count(proxysql); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| diag("After '%s': warning_count=%u, rows=%u", show_query, warning_count_after_show, row_count); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ok(warning_count_after_query == 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "WARNING_QUERY should produce warning. warning_count=%u", warning_count_after_query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ok(warning_count_after_show == 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "'%s' should return warning_count=0 in EOF packet. Actual=%u", show_query, warning_count_after_show); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mysql_close(proxysql); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mysql_close(proxysql_admin); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return exit_status(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
To improve efficiency, you can avoid calling
strlen, which scans the entire string. A more performant approach for an exact match check is to usestrncasecmpand then verify the string ends with a null terminator right after the matched part.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.
Keeping the current style for consistency with the rest of the codebase
e.g.,
proxysql/lib/mysql_connection.cpp
Line 2795 in 2637d28