diff --git a/include/set_parser.h b/include/set_parser.h index 36391d15ae..5421868342 100644 --- a/include/set_parser.h +++ b/include/set_parser.h @@ -7,6 +7,7 @@ #include "re2/re2.h" #include "re2/regexp.h" +//#define PARSERDEBUG class SetParser { private: diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index f1a17a2150..fec4d366b3 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -1075,7 +1075,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() { variables.free_connections_pct=10; variables.connect_retries_delay=1; variables.monitor_enabled=true; - variables.monitor_history=600000; + variables.monitor_history=7200000; // changed in 2.6.0 : was 600000 variables.monitor_connect_interval=120000; variables.monitor_connect_timeout=600; variables.monitor_ping_interval=8000; @@ -1114,8 +1114,8 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() { variables.automatic_detect_sqli=false; variables.firewall_whitelist_enabled=false; variables.firewall_whitelist_errormsg = strdup((char *)"Firewall blocked this query"); - variables.use_tcp_keepalive=false; - variables.tcp_keepalive_time=0; + variables.use_tcp_keepalive=true; // changed in 2.6.0 , was false + variables.tcp_keepalive_time=120; // changed in 2.6.0 , was 0 variables.throttle_connections_per_sec_to_hostgroup=1000000; variables.max_transaction_idle_time=4*3600*1000; variables.max_transaction_time=4*3600*1000; @@ -1141,7 +1141,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() { variables.query_processor_iterations=0; variables.query_processor_regex=1; variables.set_query_lock_on_hostgroup=1; - variables.set_parser_algorithm=1; // in 2.6.0 this must become 2 + variables.set_parser_algorithm=2; // before 2.6.0 this was 1 variables.reset_connection_algorithm=2; variables.auto_increment_delay_multiplex=5; variables.auto_increment_delay_multiplex_timeout_ms=10000; @@ -1161,7 +1161,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() { variables.default_schema=strdup((char *)"information_schema"); variables.handle_unknown_charset=1; variables.interfaces=strdup((char *)""); - variables.server_version=strdup((char *)"5.5.30"); + variables.server_version=strdup((char *)"8.0.11"); // changed in 2.6.0 , was 5.5.30 variables.eventslog_filename=strdup((char *)""); // proxysql-mysql-eventslog is recommended variables.eventslog_filesize=100*1024*1024; variables.eventslog_default_log=0; @@ -1174,7 +1174,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() { variables.poll_timeout=2000; variables.poll_timeout_on_failure=100; variables.have_compress=true; - variables.have_ssl = false; // disable by default for performance reason + variables.have_ssl = true; // changed in 2.6.0 , was false by default for performance reason variables.commands_stats=true; variables.multiplexing=true; variables.log_unhealthy_connections=true; @@ -1218,7 +1218,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() { variables.session_debug=true; #endif /*debug */ variables.query_digests_grouping_limit = 3; - variables.query_digests_groups_grouping_limit= 0; + variables.query_digests_groups_grouping_limit= 10; // changed in 2.6.0 , was 0 variables.enable_client_deprecate_eof=true; variables.enable_server_deprecate_eof=true; variables.enable_load_data_local_infile=false; diff --git a/lib/set_parser.cpp b/lib/set_parser.cpp index 807daef213..729dfa6c2c 100644 --- a/lib/set_parser.cpp +++ b/lib/set_parser.cpp @@ -79,6 +79,8 @@ std::map> SetParser::parse1() { re2::RE2 re0("^\\s*SET\\s+", *opt2); re2::RE2::Replace(&query, re0, ""); + re2::RE2 re1("(\\s|;)+$", *opt2); // remove trailing spaces and semicolon + re2::RE2::Replace(&query, re1, ""); std::map> result; @@ -176,12 +178,32 @@ void SetParser::generateRE_parse1v2() { string vp = "NULL"; // NULL var_patterns.push_back(vp); - vp = "\\w+"; // single word - var_patterns.push_back(vp); - for (auto it = quote_symbol.begin(); it != quote_symbol.end(); it++) { - string s = *it + vp + *it; - var_patterns.push_back(s); // add with quote + //vp = "\\w+"; // single word + //var_patterns.push_back(vp); + { + string vp0 = "(?:\\w|\\d)+"; // single word with letters and digits , for example utf8mb4 and latin1 + //var_patterns.push_back(vp); +/* + string vp1 = "(?:" + vp0 + "(?:," + vp0 + ")*)"; // multiple words (letters and digits) separated by commas WITHOUT any spaces between words . Used also for sql_mode , example: ONLY_FULL_GROUP_BY,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO + //var_patterns.push_back(vp1); // do NOT add without quote + for (auto it = quote_symbol.begin(); it != quote_symbol.end(); it++) { + string s = *it + vp1 + *it; + var_patterns.push_back(s); // add with quote + } +*/ + string vp2 = "(?:" + vp0 + "(?:-" + vp0 + ")*)"; // multiple words (letters and digits) separated by dash, WITHOUT any spaces between words . Used also for transaction isolation + var_patterns.push_back(vp2); + for (auto it = quote_symbol.begin(); it != quote_symbol.end(); it++) { + string s = *it + vp2 + *it; + var_patterns.push_back(s); // add with quote + } } + //vp = "(?:\\w|\\d)+(?:-|\\w|\\d+)*"; // multiple words (letters and digits) separated by dash, WITHOUT any spaces between words . Used ialso for transaction isolation + //var_patterns.push_back(vp); +// for (auto it = quote_symbol.begin(); it != quote_symbol.end(); it++) { +// string s = *it + vp + *it; +// var_patterns.push_back(s); // add with quote +// } vp = "\\w+(?:,\\w+)+"; // multiple words separated by commas, WITHOUT any spaces between words // NOTE: we do not use multiple words without quotes @@ -339,6 +361,9 @@ std::map> SetParser::parse1v2() { re2::RE2 re0("^\\s*SET\\s+", *parse1v2_opt2); re2::RE2::Replace(&query, re0, ""); + re2::RE2 re1("(\\s|;)+$", *parse1v2_opt2); // remove trailing spaces and semicolon + re2::RE2::Replace(&query, re1, ""); + VALGRIND_ENABLE_ERROR_REPORTING; std::string var; std::string value1, value2, value3, value4, value5; @@ -361,6 +386,7 @@ VALGRIND_ENABLE_ERROR_REPORTING; } } else if (value4 != "") { // VARIABLE + remove_quotes(value4); if (strcasecmp("transaction_isolation", value4.c_str()) == 0) { value4 = "tx_isolation"; } else if (strcasecmp("transaction_read_only", value4.c_str()) == 0) { diff --git a/test/tap/tests/reg_test_3427-stmt_first_comment1-t.cpp b/test/tap/tests/reg_test_3427-stmt_first_comment1-t.cpp index 4b03f23fdc..2e2e505374 100644 --- a/test/tap/tests/reg_test_3427-stmt_first_comment1-t.cpp +++ b/test/tap/tests/reg_test_3427-stmt_first_comment1-t.cpp @@ -123,6 +123,7 @@ int main(int argc, char** argv) { }; std::string update_mysql_queries {}; string_format(t_update_mysql_servers, update_mysql_queries, WRITER_HOSTGROUP_ID); + diag("Line:%d , Running query: %s", __LINE__ , update_mysql_queries.c_str()); MYSQL_QUERY(proxysql_admin, update_mysql_queries.c_str()); MYSQL_QUERY(proxysql_admin, "LOAD MYSQL SERVERS TO RUNTIME"); @@ -133,10 +134,13 @@ int main(int argc, char** argv) { std::string max_stmt_query {}; string_format(t_max_stmt_query, max_stmt_query, MAX_STMT_NUM_QUERIES); MYSQL_QUERY(proxysql_admin, max_stmt_query.c_str()); + diag("Line:%d , Running query: %s", __LINE__ , max_stmt_query.c_str()); MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); uint32_t query_id = 0; + int rc = 0; + for (uint32_t i = 0; i < RESET_CONNECTION_QUERIES; i++) { if (i <= MAX_STMT_NUM_QUERIES) { query_id = i; @@ -159,20 +163,23 @@ int main(int argc, char** argv) { string_format(query_t, query, query_id); MYSQL_STMT* stmt = mysql_stmt_init(proxysql_mysql); + ok(stmt != NULL , "mysql_stmt_init() succeeded"); if (!stmt) { diag("mysql_stmt_init(), out of memory"); res = EXIT_FAILURE; goto exit; } - ok(stmt != NULL , "mysql_stmt_init() succeeded"); - if (mysql_stmt_prepare(stmt, query.c_str(), strlen(query.c_str()))) { + diag("Line:%d , Preparing query: %s", __LINE__ , query.c_str()); + rc = mysql_stmt_prepare(stmt, query.c_str(), strlen(query.c_str())); + ok(rc == 0, "mysql_stmt_prepare() succeeded"); + if (rc) { diag("mysql_stmt_prepare at line %d failed: %s", __LINE__ , mysql_error(proxysql_mysql)); mysql_close(proxysql_mysql); res = EXIT_FAILURE; goto exit; } else { - ok(1,"mysql_stmt_prepare() succeeded"); + // } if (param) { @@ -194,7 +201,9 @@ int main(int argc, char** argv) { } } - if (mysql_stmt_execute(stmt)) { + rc = mysql_stmt_execute(stmt); + ok(rc == 0, "mysql_stmt_execute() succeeded"); + if (rc) { diag( "mysql_stmt_execute at line %d failed: %s", __LINE__ , mysql_stmt_error(stmt) @@ -202,7 +211,7 @@ int main(int argc, char** argv) { res = EXIT_FAILURE; goto exit; } else { - ok(1,"mysql_stmt_execute() succeeded"); + // } MYSQL_BIND bind[3]; @@ -233,7 +242,9 @@ int main(int argc, char** argv) { bind[2].length = &length[2]; bind[2].error = &error[2]; - if (mysql_stmt_bind_result(stmt, bind)) { + rc = mysql_stmt_bind_result(stmt, bind); + ok(rc == 0, "mysql_stmt_bind_result() succeeded"); + if (rc) { diag( "mysql_stmt_bind_result at line %d failed: %s", __LINE__, mysql_stmt_error(stmt) @@ -241,10 +252,12 @@ int main(int argc, char** argv) { res = EXIT_FAILURE; goto exit; } else { - ok(1,"mysql_stmt_bind_result() succeeded"); + // } - if (mysql_stmt_fetch(stmt) == 1) { + rc = mysql_stmt_fetch(stmt); + ok(rc == 0,"mysql_stmt_fetch() succeeded"); + if (rc == 1) { diag( "mysql_stmt_fetch at line %d failed: %s", __LINE__, mysql_stmt_error(stmt) @@ -252,7 +265,7 @@ int main(int argc, char** argv) { res = EXIT_FAILURE; goto exit; } else { - ok(1,"mysql_stmt_fetch() succeeded"); + // } bool data_match_expected = diff --git a/test/tap/tests/test_filtered_set_statements-t.cpp b/test/tap/tests/test_filtered_set_statements-t.cpp index fee2dee096..726050ac62 100644 --- a/test/tap/tests/test_filtered_set_statements-t.cpp +++ b/test/tap/tests/test_filtered_set_statements-t.cpp @@ -28,7 +28,7 @@ * TODO: Fill with all the statements that should be properly handled by ProxySQL. */ std::vector> filtered_set_queries { - { "sql_mode", "ONLY_FULL_GROUP_BY,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO" }, + { "sql_mode", "'ONLY_FULL_GROUP_BY,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO'" }, { "wait_timeout", "28801" }, { "character_set_results", "latin1" }, { "character_set_connection", "latin1" },