From 3790ce6d825c08088ae16e3987610f7487609ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Tue, 26 Mar 2024 22:36:11 +0000 Subject: [PATCH 1/3] Do not print "Updating metadata for stmt" for EXPLAIN ProxySQL generates warnings when updating prepared statements metadatas. This commit filters these warnings for EXPLAIN statements. See #4478 It also include a TAP test for code coverage. --- lib/MySQL_PreparedStatement.cpp | 6 ++- test/tap/tests/stmt_explain-t.cpp | 73 +++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 test/tap/tests/stmt_explain-t.cpp diff --git a/lib/MySQL_PreparedStatement.cpp b/lib/MySQL_PreparedStatement.cpp index e9263a33d7..5a47e81119 100644 --- a/lib/MySQL_PreparedStatement.cpp +++ b/lib/MySQL_PreparedStatement.cpp @@ -418,7 +418,11 @@ void MySQL_STMT_Global_info::update_metadata(MYSQL_STMT *stmt) { } } if (need_refresh) { - proxy_warning("Updating metadata for stmt %lu , user %s, query %s\n", statement_id, username, query); + if (digest_text && strncasecmp(digest_text, "EXPLAIN", strlen("EXPLAIN"))==0) { + // do not print any message in case of EXPLAIN + } else { + proxy_warning("Updating metadata for stmt %lu , user %s, query %s\n", statement_id, username, query); + } // from here is copied from destructor if (num_columns) { uint16_t i; diff --git a/test/tap/tests/stmt_explain-t.cpp b/test/tap/tests/stmt_explain-t.cpp new file mode 100644 index 0000000000..f61f1b77b6 --- /dev/null +++ b/test/tap/tests/stmt_explain-t.cpp @@ -0,0 +1,73 @@ +/** + * @file stmt_explain-t.cpp + * @brief executes EXPLAIN using prepared statements. + * It doesn't perform any real test, only code coverage. + */ + + +#include +#include +#include +#include + +#include "mysql.h" + +#include "tap.h" +#include "command_line.h" +#include "utils.h" + +using std::string; + + +int main(int argc, char** argv) { + CommandLine cl; + + // Checking for required environmental variables + if (cl.getEnv()) { + diag("Failed to get the required environmental variables."); + return -1; + } + + plan(1); // Plan for testing purposes + + MYSQL* mysql = mysql_init(NULL); ///< MySQL connection object + if (!mysql) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); + return exit_status(); + } + + // Connecting to ProxySQL + diag("Connecting to '%s@%s:%d'", cl.mysql_username, cl.mysql_host, cl.port); + if (!mysql_real_connect(mysql, cl.mysql_host, cl.mysql_username, cl.mysql_password, NULL, cl.port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); + return exit_status(); + } + + // Initialize and prepare all the statements + MYSQL_STMT* stmt = mysql_stmt_init(mysql); + if (!stmt) { + fprintf(stderr, "mysql_stmt_init(), out of memory\n"); + return exit_status(); + } + + std::string select_query = "EXPLAIN SELECT 1"; + diag("select_query: %s", select_query.c_str()); + if (mysql_stmt_prepare(stmt, select_query.c_str(), strlen(select_query.c_str()))) { + fprintf(stderr, "mysql_stmt_prepare at line %d failed: %s\n", __LINE__ , mysql_error(mysql)); + mysql_close(mysql); + mysql_library_end(); + return exit_status(); + } + + int rc = mysql_stmt_execute(stmt); + ok (rc == 0 , "mysql_stmt_execute() succeeded"); + if (rc) { + fprintf(stderr, "mysql_stmt_execute at line %d failed: %d , %s\n", __LINE__ , rc , mysql_stmt_error(stmt)); + mysql_close(mysql); + mysql_library_end(); + return exit_status(); + } + mysql_close(mysql); + + return exit_status(); +} From 115ba18de48b43e02726682e59ec8ebe336770fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Thu, 28 Mar 2024 10:05:58 +0000 Subject: [PATCH 2/3] Updated TAP test to use cl.host instead of cl.mysql_host --- test/tap/tests/stmt_explain-t.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tap/tests/stmt_explain-t.cpp b/test/tap/tests/stmt_explain-t.cpp index f61f1b77b6..d03a3fae69 100644 --- a/test/tap/tests/stmt_explain-t.cpp +++ b/test/tap/tests/stmt_explain-t.cpp @@ -37,8 +37,8 @@ int main(int argc, char** argv) { } // Connecting to ProxySQL - diag("Connecting to '%s@%s:%d'", cl.mysql_username, cl.mysql_host, cl.port); - if (!mysql_real_connect(mysql, cl.mysql_host, cl.mysql_username, cl.mysql_password, NULL, cl.port, NULL, 0)) { + diag("Connecting to '%s@%s:%d'", cl.mysql_username, cl.host, cl.port); + if (!mysql_real_connect(mysql, cl.host, cl.mysql_username, cl.mysql_password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); } From 0a00083bda05eb8324617896875c4a0a19931aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Thu, 28 Mar 2024 10:08:15 +0000 Subject: [PATCH 3/3] Updated TAP test to use cl.host instead of cl.mysql_host --- test/tap/tests/reg_test_3371_prepared_statement_crash-t.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tap/tests/reg_test_3371_prepared_statement_crash-t.cpp b/test/tap/tests/reg_test_3371_prepared_statement_crash-t.cpp index 0f929cba53..db6cfa1168 100644 --- a/test/tap/tests/reg_test_3371_prepared_statement_crash-t.cpp +++ b/test/tap/tests/reg_test_3371_prepared_statement_crash-t.cpp @@ -39,8 +39,8 @@ int main(int argc, char** argv) { } // Connecting to ProxySQL - diag("Connecting to '%s@%s:%d'", cl.mysql_username, cl.mysql_host, cl.port); - if (!mysql_real_connect(mysql, cl.mysql_host, cl.mysql_username, cl.mysql_password, NULL, cl.port, NULL, 0)) { + diag("Connecting to '%s@%s:%d'", cl.mysql_username, cl.host, cl.port); + if (!mysql_real_connect(mysql, cl.host, cl.mysql_username, cl.mysql_password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); }