From 9999650bbe8dc47e480d33581b84a2b6bd5065ce Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 13 May 2020 10:30:39 +0300 Subject: [PATCH 1/2] MXS-2990 Add test that reveals problem Had to fix qc_mysqlembedded as well to work with 10.2. --- query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc | 3 ++- query_classifier/test/expected.sql | 1 + query_classifier/test/input.sql | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc index 3913d0a82..4599ed0d2 100644 --- a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc +++ b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc @@ -2180,7 +2180,8 @@ int32_t qc_mysql_get_preparable_stmt(GWBUF* stmt, GWBUF** preparable_stmt) { const char* preparable_stmt; size_t preparable_stmt_len; -#if MYSQL_VERSION_MINOR >= 3 +// MYSQL_VERSION_PATCH might be smaller, but this was detected with 10.2.32. +#if MYSQL_VERSION_MINOR >= 3 || (MYSQL_VERSION_MINOR == 2 && MYSQL_VERSION_PATCH >= 32) preparable_stmt = lex->prepared_stmt_code->str_value.ptr(); preparable_stmt_len = lex->prepared_stmt_code->str_value.length(); #else diff --git a/query_classifier/test/expected.sql b/query_classifier/test/expected.sql index f4816b1fe..ae7b22f3a 100644 --- a/query_classifier/test/expected.sql +++ b/query_classifier/test/expected.sql @@ -34,3 +34,4 @@ QUERY_TYPE_SESSION_WRITE|QUERY_TYPE_USERVAR_WRITE QUERY_TYPE_READ|QUERY_TYPE_MASTER_READ QUERY_TYPE_WRITE QUERY_TYPE_READ +QUERY_TYPE_WRITE diff --git a/query_classifier/test/input.sql b/query_classifier/test/input.sql index 5c8fbc549..bf00b8b78 100644 --- a/query_classifier/test/input.sql +++ b/query_classifier/test/input.sql @@ -34,3 +34,4 @@ SET @saved_cs_client= @@character_set_client; SELECT 1 AS c1 FROM t1 ORDER BY ( SELECT 1 AS c2 FROM t1 GROUP BY GREATEST(LAST_INSERT_ID(), t1.a) ORDER BY GREATEST(LAST_INSERT_ID(), t1.a) LIMIT 1); SET PASSWORD FOR 'user'@'10.0.0.1'='*C50EB75D7CB4C76B5264218B92BC69E6815B057A'; SELECT UTC_TIMESTAMP(); +SELECT COUNT(IF(!c.ispackage, 1, NULL)) as cnt FROM test FOR UPDATE; From b212117fd304a9c64e191a839bc72c206d332e0a Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 13 May 2020 10:38:07 +0300 Subject: [PATCH 2/2] MXS-2990 Fix the problem, treat ! as not If '!' is followed by '=' then it is NOT-EQUAL, otherwise it is just NOT. --- query_classifier/qc_sqlite/sqlite-src-3110100/src/tokenize.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/query_classifier/qc_sqlite/sqlite-src-3110100/src/tokenize.c b/query_classifier/qc_sqlite/sqlite-src-3110100/src/tokenize.c index 05070b107..fc958424b 100644 --- a/query_classifier/qc_sqlite/sqlite-src-3110100/src/tokenize.c +++ b/query_classifier/qc_sqlite/sqlite-src-3110100/src/tokenize.c @@ -419,8 +419,13 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ } case CC_BANG: { if( z[1]!='=' ){ +#ifdef MAXSCALE + *tokenType = TK_NOT; + return 1; +#else *tokenType = TK_ILLEGAL; return 2; +#endif }else{ *tokenType = TK_NE; return 2;