From 0737d8f35d68371137a702ef83e3e00c0d6af6cf Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Sat, 26 Apr 2025 13:50:30 +0700 Subject: [PATCH] MDEV-33281 Fix mysql-test-run to correctly handle hints After commit 408a637b87cba62506a4fbf363424ccc8530df12 for MDEV-29344 the mysql-test framework started to misinterpret slash/star sequences for statements looking like this: SELECT /* BNL(t1) */* FROM t1, t2 where there is no space after closing `*/` and the following `*`. This commit fixes that misinterpretation --- client/mysqltest.cc | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index d77dfffb3ff..08e96c2fbe2 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -6818,7 +6818,7 @@ int read_line() my_bool have_slash= FALSE; enum {R_NORMAL, R_Q, R_SLASH_IN_Q, - R_COMMENT, R_LINE_START, R_CSTYLE_COMMENT} state= R_LINE_START; + R_COMMENT, R_LINE_START, R_CSTYLE_COMMENT, R_HINT} state= R_LINE_START; DBUG_ENTER("read_line"); *p= 0; @@ -6875,8 +6875,10 @@ int read_line() p--; } + bool drop_last_char= false; switch(state) { case R_NORMAL: + case R_HINT: if (end_of_query(c)) { *p= 0; @@ -6910,16 +6912,29 @@ int read_line() state= R_CSTYLE_COMMENT; break; } + else if (c == '/' && last_char == '*') // Closing sequence `*/` + { + state= R_NORMAL; + // The hint is finished, and we don't want to interpret the current slash + // as an opener for a next hint or a C-style comment like it can happen + // for a statement like `SELECT /*+ BNL(t1) */* FROM t1` where there is + //no space between `*/` and `*`. So discard the current slash + drop_last_char= true; + } have_slash= is_escape_char(c, last_quote); break; case R_CSTYLE_COMMENT: - if (c == '!') - // Got the hint introducer '/*!'. Switch to normal processing of - // next following characters - state= R_NORMAL; + if (c == '!' || c == '+') + { + // Got hint introducer '/*!' or '/*+' + state= R_HINT; + } else if (c == '/' && last_char == '*') + { state= R_NORMAL; + drop_last_char= true; // See comment for `drop_last_char` above + } break; case R_COMMENT: @@ -6999,7 +7014,15 @@ int read_line() } - last_char= c; + if (!drop_last_char) + { + last_char= c; + } + else + { + last_char= 0; + drop_last_char= false; + } if (!skip_char) {