Skip to content

Commit

Permalink
Merge pull request #4340 from sysown/v2.x-2.6_new_defaults_2
Browse files Browse the repository at this point in the history
V2.x new default for mysql-set_parser_algorithm
  • Loading branch information
renecannao authored Dec 4, 2023
2 parents 91b04d5 + 2ddc818 commit 8fdc7f0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
1 change: 1 addition & 0 deletions include/set_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "re2/re2.h"
#include "re2/regexp.h"

//#define PARSERDEBUG

class SetParser {
private:
Expand Down
3 changes: 1 addition & 2 deletions lib/MySQL_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,8 +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;
// FIXME: this must become 2 in 2.6.0
variables.set_parser_algorithm=1; // before 2.6.0 this was 1 , 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;
Expand Down
36 changes: 31 additions & 5 deletions lib/set_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ std::map<std::string,std::vector<std::string>> 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<std::string,std::vector<std::string>> result;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -339,6 +361,9 @@ std::map<std::string,std::vector<std::string>> 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;
Expand All @@ -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) {
Expand Down
31 changes: 22 additions & 9 deletions test/tap/tests/reg_test_3427-stmt_first_comment1-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -194,15 +201,17 @@ 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)
);
res = EXIT_FAILURE;
goto exit;
} else {
ok(1,"mysql_stmt_execute() succeeded");
//
}

MYSQL_BIND bind[3];
Expand Down Expand Up @@ -233,26 +242,30 @@ 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)
);
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)
);
res = EXIT_FAILURE;
goto exit;
} else {
ok(1,"mysql_stmt_fetch() succeeded");
//
}

bool data_match_expected =
Expand Down
2 changes: 1 addition & 1 deletion test/tap/tests/test_filtered_set_statements-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* TODO: Fill with all the statements that should be properly handled by ProxySQL.
*/
std::vector<std::pair<std::string, std::string>> 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" },
Expand Down

0 comments on commit 8fdc7f0

Please sign in to comment.