From 408a637b87cba62506a4fbf363424ccc8530df12 Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Fri, 14 Mar 2025 12:43:22 +0700 Subject: [PATCH] MDEV-29344: engines/iuds.insert_time cannot run with PS protocol (syntax error) The syntax error produced on running the test engines/iuds.insert_time in PS-mode was caused by presence of the C-Style comment containing the single quote at the end of SQL statement, something like the following one: /* doesn't throw error */; Presence of the single quote was interpreted by mysqltest utility as indication of real string literal, that resulted in consuming every characters following that mark as a literal, including the delimiter character ';'. It led to concatenation of lines into a single multi-statement that was sent from mysqltest to MariaDB server for processing. In case mysqltest is run in regular mode (that is, not PS-mode), multi-statement is handled successfully on server side, but in case PS-mode is on, multi-statement is supplied in COM_STMT_PREPARE that caused the parsing error since multi-statements is not supported by statement prepare command. To fix the issue, in case mysqltest encounters the C-Style comment is should switch to reading next following characters without any processing until it hit the closing C-style comment marks '*/', with one exception if the sequence of characters '/*' followed by the exclamation mark, that means the hint introducer has been read. --- client/mysqltest.cc | 16 +++++++++++++++- mysql-test/main/mysqltest.result | 9 +++++++++ mysql-test/main/mysqltest.test | 6 ++++++ .../suite/engines/iuds/r/insert_time.result | 4 ++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 2ff00260c05..14f1d7a981c 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -6744,7 +6744,7 @@ int read_line() my_bool have_slash= FALSE; enum {R_NORMAL, R_Q, R_SLASH_IN_Q, - R_COMMENT, R_LINE_START} state= R_LINE_START; + R_COMMENT, R_LINE_START, R_CSTYLE_COMMENT} state= R_LINE_START; DBUG_ENTER("read_line"); *p= 0; @@ -6831,9 +6831,23 @@ int read_line() state= R_Q; } } + else if (c == '*' && last_char == '/') + { + state= R_CSTYLE_COMMENT; + break; + } 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; + else if (c == '/' && last_char == '*') + state= R_NORMAL; + break; + case R_COMMENT: if (c == '\n') { diff --git a/mysql-test/main/mysqltest.result b/mysql-test/main/mysqltest.result index 478ef82ca1f..fbc723bbe1d 100644 --- a/mysql-test/main/mysqltest.result +++ b/mysql-test/main/mysqltest.result @@ -989,4 +989,13 @@ select "foo\""bar"; foo\"bar foo\"bar set sql_mode=default; +# +# MDEV-29344: engines/iuds.insert_time cannot run with PS protocol (syntax error) +# +SELECT 1 /* doesn't throw error */; +1 +1 +SELECT 1 /* doesn't throw error */; +1 +1 End of tests diff --git a/mysql-test/main/mysqltest.test b/mysql-test/main/mysqltest.test index b545e354040..4895d06f66e 100644 --- a/mysql-test/main/mysqltest.test +++ b/mysql-test/main/mysqltest.test @@ -2954,6 +2954,12 @@ set sql_mode=no_backslash_escapes; select "foo\""bar"; set sql_mode=default; +--echo # +--echo # MDEV-29344: engines/iuds.insert_time cannot run with PS protocol (syntax error) +--echo # +SELECT 1 /* doesn't throw error */; +SELECT 1 /* doesn't throw error */; + --echo End of tests # Wait till we reached the initial number of concurrent sessions diff --git a/mysql-test/suite/engines/iuds/r/insert_time.result b/mysql-test/suite/engines/iuds/r/insert_time.result index fdda49a36c1..5bfc3b7893b 100644 --- a/mysql-test/suite/engines/iuds/r/insert_time.result +++ b/mysql-test/suite/engines/iuds/r/insert_time.result @@ -5073,10 +5073,14 @@ ERROR 23000: Duplicate entry '825:23:00' for key 'c2' INSERT INTO t3(c1,c2) VALUES('34 9:23','34 9:23') /* throws error as row exists with c1='34 9:23',c2='34 9:23' */; ERROR 23000: Duplicate entry '825:23:00-825:23:00' for key 'idx' INSERT IGNORE INTO t1(c1,c2) VALUES('10:22:33','10:22:34') /* doesn't throw error */; +Warnings: +Warning 1062 Duplicate entry '10:22:33' for key 'PRIMARY' INSERT IGNORE INTO t2(c1,c2) VALUES('12:34:56.78','12:34:56.78') /*doesn't throw error */; Warnings: Warning 1062 Duplicate entry '12:34:56-12:34:56' for key 'PRIMARY' INSERT IGNORE INTO t1(c1,c2) VALUES('10:22:34','34 9:23') /*doesn't throw error */; +Warnings: +Warning 1062 Duplicate entry '825:23:00' for key 'c2' INSERT IGNORE INTO t3(c1,c2) VALUES('34 9:23','34 9:23') /*doesn't throw error */; Warnings: Warning 1062 Duplicate entry '825:23:00-825:23:00' for key 'idx'