From 2d89f06a5afb5c3c2b53bd6acd4e1cd5729919e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Tue, 30 Apr 2024 00:28:08 +0000 Subject: [PATCH] Refactoring of ProcessQueryAndSetStatusFlags() --- include/mysql_connection.h | 4 ++ lib/mysql_connection.cpp | 130 ++++++++++++++++++++++--------------- 2 files changed, 80 insertions(+), 54 deletions(-) diff --git a/include/mysql_connection.h b/include/mysql_connection.h index 7696866c71..f88e41eb35 100644 --- a/include/mysql_connection.h +++ b/include/mysql_connection.h @@ -65,6 +65,10 @@ class MySQL_Connection { void connect_start_SetClientFlag(unsigned long&); char * connect_start_DNS_lookup(); void connect_start_SetSslSettings(); + void ProcessQueryAndSetStatusFlags_Warnings(char *); + void ProcessQueryAndSetStatusFlags_UserVariables(char *, int); + void ProcessQueryAndSetStatusFlags_Savepoint(char *); + void ProcessQueryAndSetStatusFlags_SetBackslashEscapes(); public: struct { char *server_version; diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index 620524da3c..252d0067d6 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -2669,24 +2669,7 @@ bool MySQL_Connection::IsKeepMultiplexEnabledVariables(char *query_digest_text) return true; } -void MySQL_Connection::ProcessQueryAndSetStatusFlags(char *query_digest_text) { - if (query_digest_text==NULL) return; - // unknown what to do with multiplex - int mul=-1; - if (myds) { - if (myds->sess) { - if (myds->sess->qpo) { - mul=myds->sess->qpo->multiplex; - if (mul==0) { - set_status(true, STATUS_MYSQL_CONNECTION_NO_MULTIPLEX); - } else { - if (mul==1) { - set_status(false, STATUS_MYSQL_CONNECTION_NO_MULTIPLEX); - } - } - } - } - } +void MySQL_Connection::ProcessQueryAndSetStatusFlags_Warnings(char *query_digest_text) { // checking warnings and disabling multiplexing will be effective only when the mysql-query_digests is enabled if (get_status(STATUS_MYSQL_CONNECTION_HAS_WARNINGS) == false) { if (warning_count > 0) { @@ -2712,7 +2695,10 @@ void MySQL_Connection::ProcessQueryAndSetStatusFlags(char *query_digest_text) { set_status(false, STATUS_MYSQL_CONNECTION_HAS_WARNINGS); } } - +} + + +void MySQL_Connection::ProcessQueryAndSetStatusFlags_UserVariables(char *query_digest_text, int mul) { if (get_status(STATUS_MYSQL_CONNECTION_USER_VARIABLE)==false) { // we search for variables only if not already set // if ( // strncasecmp(query_digest_text,"SELECT @@tx_isolation", strlen("SELECT @@tx_isolation")) @@ -2757,41 +2743,9 @@ void MySQL_Connection::ProcessQueryAndSetStatusFlags(char *query_digest_text) { } } } - if (get_status(STATUS_MYSQL_CONNECTION_PREPARED_STATEMENT)==false) { // we search if prepared was already executed - if (!strncasecmp(query_digest_text,"PREPARE ", strlen("PREPARE "))) { - set_status(true, STATUS_MYSQL_CONNECTION_PREPARED_STATEMENT); - } - } - if (get_status(STATUS_MYSQL_CONNECTION_TEMPORARY_TABLE)==false) { // we search for temporary if not already set - if (!strncasecmp(query_digest_text,"CREATE TEMPORARY TABLE ", strlen("CREATE TEMPORARY TABLE "))) { - set_status(true, STATUS_MYSQL_CONNECTION_TEMPORARY_TABLE); - } - } - if (get_status(STATUS_MYSQL_CONNECTION_LOCK_TABLES)==false) { // we search for lock tables only if not already set - if (!strncasecmp(query_digest_text,"LOCK TABLE", strlen("LOCK TABLE"))) { - set_status(true, STATUS_MYSQL_CONNECTION_LOCK_TABLES); - } - } - if (get_status(STATUS_MYSQL_CONNECTION_LOCK_TABLES)==false) { // we search for lock tables only if not already set - if (!strncasecmp(query_digest_text,"FLUSH TABLES WITH READ LOCK", strlen("FLUSH TABLES WITH READ LOCK"))) { // issue 613 - set_status(true, STATUS_MYSQL_CONNECTION_LOCK_TABLES); - } - } - if (get_status(STATUS_MYSQL_CONNECTION_LOCK_TABLES)==true) { - if (!strncasecmp(query_digest_text,"UNLOCK TABLES", strlen("UNLOCK TABLES"))) { - set_status(false, STATUS_MYSQL_CONNECTION_LOCK_TABLES); - } - } - if (get_status(STATUS_MYSQL_CONNECTION_GET_LOCK)==false) { // we search for get_lock if not already set - if (strcasestr(query_digest_text,"GET_LOCK(")) { - set_status(true, STATUS_MYSQL_CONNECTION_GET_LOCK); - } - } - if (get_status(STATUS_MYSQL_CONNECTION_FOUND_ROWS)==false) { // we search for SQL_CALC_FOUND_ROWS if not already set - if (strcasestr(query_digest_text,"SQL_CALC_FOUND_ROWS")) { - set_status(true, STATUS_MYSQL_CONNECTION_FOUND_ROWS); - } - } +} + +void MySQL_Connection::ProcessQueryAndSetStatusFlags_Savepoint(char *query_digest_text) { if (get_status(STATUS_MYSQL_CONNECTION_HAS_SAVEPOINT)==false) { if (mysql) { if ( @@ -2821,6 +2775,9 @@ void MySQL_Connection::ProcessQueryAndSetStatusFlags(char *query_digest_text) { set_status(false, STATUS_MYSQL_CONNECTION_HAS_SAVEPOINT); } } +} + +void MySQL_Connection::ProcessQueryAndSetStatusFlags_SetBackslashEscapes() { if (mysql) { if (myds && myds->sess) { if (myds->sess->client_myds && myds->sess->client_myds->myconn) { @@ -2834,6 +2791,71 @@ void MySQL_Connection::ProcessQueryAndSetStatusFlags(char *query_digest_text) { } } +void MySQL_Connection::ProcessQueryAndSetStatusFlags(char *query_digest_text) { + if (query_digest_text==NULL) return; + // unknown what to do with multiplex + int mul=-1; + if (myds) { + if (myds->sess) { + if (myds->sess->qpo) { + mul=myds->sess->qpo->multiplex; + if (mul==0) { + set_status(true, STATUS_MYSQL_CONNECTION_NO_MULTIPLEX); + } else { + if (mul==1) { + set_status(false, STATUS_MYSQL_CONNECTION_NO_MULTIPLEX); + } + } + } + } + } + + ProcessQueryAndSetStatusFlags_Warnings(query_digest_text); + + ProcessQueryAndSetStatusFlags_UserVariables(query_digest_text, mul); + + if (get_status(STATUS_MYSQL_CONNECTION_PREPARED_STATEMENT)==false) { // we search if prepared was already executed + if (!strncasecmp(query_digest_text,"PREPARE ", strlen("PREPARE "))) { + set_status(true, STATUS_MYSQL_CONNECTION_PREPARED_STATEMENT); + } + } + if (get_status(STATUS_MYSQL_CONNECTION_TEMPORARY_TABLE)==false) { // we search for temporary if not already set + if (!strncasecmp(query_digest_text,"CREATE TEMPORARY TABLE ", strlen("CREATE TEMPORARY TABLE "))) { + set_status(true, STATUS_MYSQL_CONNECTION_TEMPORARY_TABLE); + } + } + if (get_status(STATUS_MYSQL_CONNECTION_LOCK_TABLES)==false) { // we search for lock tables only if not already set + if (!strncasecmp(query_digest_text,"LOCK TABLE", strlen("LOCK TABLE"))) { + set_status(true, STATUS_MYSQL_CONNECTION_LOCK_TABLES); + } + } + if (get_status(STATUS_MYSQL_CONNECTION_LOCK_TABLES)==false) { // we search for lock tables only if not already set + if (!strncasecmp(query_digest_text,"FLUSH TABLES WITH READ LOCK", strlen("FLUSH TABLES WITH READ LOCK"))) { // issue 613 + set_status(true, STATUS_MYSQL_CONNECTION_LOCK_TABLES); + } + } + if (get_status(STATUS_MYSQL_CONNECTION_LOCK_TABLES)==true) { + if (!strncasecmp(query_digest_text,"UNLOCK TABLES", strlen("UNLOCK TABLES"))) { + set_status(false, STATUS_MYSQL_CONNECTION_LOCK_TABLES); + } + } + if (get_status(STATUS_MYSQL_CONNECTION_GET_LOCK)==false) { // we search for get_lock if not already set + if (strcasestr(query_digest_text,"GET_LOCK(")) { + set_status(true, STATUS_MYSQL_CONNECTION_GET_LOCK); + } + } + if (get_status(STATUS_MYSQL_CONNECTION_FOUND_ROWS)==false) { // we search for SQL_CALC_FOUND_ROWS if not already set + if (strcasestr(query_digest_text,"SQL_CALC_FOUND_ROWS")) { + set_status(true, STATUS_MYSQL_CONNECTION_FOUND_ROWS); + } + } + + ProcessQueryAndSetStatusFlags_Savepoint(query_digest_text); + + ProcessQueryAndSetStatusFlags_SetBackslashEscapes(); + +} + void MySQL_Connection::optimize() { if (mysql->net.max_packet > 65536) { // FIXME: temporary, maybe for very long time . This needs to become a global variable if ( ( mysql->net.buff == mysql->net.read_pos ) && ( mysql->net.read_pos == mysql->net.write_pos ) ) {