@@ -1135,12 +1135,6 @@ bool MySQL_Session::handler_special_queries(PtrSize_t *pkt) {
11351135 }
11361136 }
11371137
1138- if (session_type != PROXYSQL_SESSION_CLICKHOUSE) {
1139- if (pkt->size >(5 +4 ) && strncasecmp ((char *)" USE " ,(char *)pkt->ptr +5 ,4 )==0 ) {
1140- handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_USE_DB (pkt);
1141- return true ;
1142- }
1143- }
11441138 if (pkt->size ==SELECT_VERSION_COMMENT_LEN+5 && strncmp ((char *)SELECT_VERSION_COMMENT,(char *)pkt->ptr +5 ,pkt->size -5 )==0 ) {
11451139 // FIXME: this doesn't return AUTOCOMMIT or IN_TRANS
11461140 PtrSize_t pkt_2;
@@ -3593,6 +3587,23 @@ int MySQL_Session::get_pkts_from_client(bool& wrong_pass, PtrSize_t& pkt) {
35933587 clock_gettime (CLOCK_THREAD_CPUTIME_ID,&begint);
35943588 }
35953589 qpo=GloQPro->process_mysql_query (this ,pkt.ptr ,pkt.size ,&CurrentQuery);
3590+ // This block was moved from 'handler_special_queries' to support
3591+ // handling of 'USE' statements which are preceded by a comment.
3592+ // For more context check issue: #3493.
3593+ // ===================================================
3594+ if (session_type != PROXYSQL_SESSION_CLICKHOUSE) {
3595+ if (strncasecmp ((char *)" USE " ,CurrentQuery.get_digest_text (),4 )==0 ) {
3596+ handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_USE_DB (&pkt, CurrentQuery.get_digest_text ());
3597+
3598+ if (mirror == false ) {
3599+ break ;
3600+ } else {
3601+ handler_ret = -1 ;
3602+ return handler_ret;
3603+ }
3604+ }
3605+ }
3606+ // ===================================================
35963607 if (qpo->max_lag_ms >= 0 ) {
35973608 thread->status_variables .stvar [st_var_queries_with_max_lag_ms]++;
35983609 }
@@ -5219,12 +5230,12 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
52195230
52205231// this function was introduced due to isseu #718
52215232// some application (like the one written in Perl) do not use COM_INIT_DB , but COM_QUERY with USE dbname
5222- void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_USE_DB (PtrSize_t *pkt) {
5233+ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_USE_DB (PtrSize_t *pkt, const char * query_digest ) {
52235234 gtid_hid=-1 ;
52245235 proxy_debug (PROXY_DEBUG_MYSQL_COM, 5 , " Got COM_QUERY with USE dbname\n " );
52255236 if (session_type == PROXYSQL_SESSION_MYSQL) {
52265237 __sync_fetch_and_add (&MyHGM->status .frontend_use_db , 1 );
5227- char *schemaname=strndup (( char *)pkt-> ptr + sizeof (mysql_hdr)+ 5 ,pkt-> size - sizeof (mysql_hdr)- 5 );
5238+ char *schemaname=strndup (query_digest+ 4 , strlen (query_digest)- 4 );
52285239 char *schemanameptr=trim_spaces_and_quotes_in_place (schemaname);
52295240 // handle cases like "USE `schemaname`
52305241 if (schemanameptr[0 ]==' `' && schemanameptr[strlen (schemanameptr)-1 ]==' `' ) {
@@ -5443,7 +5454,11 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
54435454#endif
54445455 if (index (dig,' ;' ) && (index (dig,' ;' ) != dig + strlen (dig)-1 )) {
54455456 string nqn = string ((char *)CurrentQuery.QueryPointer ,CurrentQuery.QueryLength );
5446- proxy_warning (" Unable to parse multi-statements command with SET statement: setting lock hostgroup . Command: %s\n " , nqn.c_str ());
5457+ proxy_warning (
5458+ " Unable to parse multi-statements command with SET statement from client"
5459+ " %s:%d: setting lock hostgroup. Command: %s\n " , client_myds->addr .addr ,
5460+ client_myds->addr .port , nqn.c_str ()
5461+ );
54475462 *lock_hostgroup = true ;
54485463 return false ;
54495464 }
0 commit comments