diff --git a/ast/testdata/TestSplitStatement.golden b/ast/testdata/TestSplitStatement.golden index a3e10ae4d3d067a0e18d74abd726ea8f0f3e69fc..deb4590c0c692be05e9aae32b7658bdd6bc04b51 100644 --- a/ast/testdata/TestSplitStatement.golden +++ b/ast/testdata/TestSplitStatement.golden @@ -36,6 +36,8 @@ where col = 1 tb; 18 -- comment +19 INSERT /*+ SET_VAR(foreign_key_checks=OFF) */ INTO t2 VALUES(2); +20 select /*!50000 1,*/ 1; 0 select * from test\Ghello 1 select 'hello\Gworld', col from test\Ghello 2 -- select * from test\Ghello diff --git a/ast/token.go b/ast/token.go index 3e1493761ad8188ec2bd0d21e585e912e4cd4edc..4267e8330d4cf252c027b649c491f324b5049108 100644 --- a/ast/token.go +++ b/ast/token.go @@ -898,8 +898,11 @@ func SplitStatement(buf []byte, delimiter []byte) (string, string, []byte) { } // multi line comment + // https://dev.mysql.com/doc/refman/8.0/en/comments.html + // https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html if b == '/' && i+1 < len(buf) && buf[i+1] == '*' { - if !multiLineComment && !singleLineComment && !quoted && buf[i+2] != '!' { + if !multiLineComment && !singleLineComment && !quoted && + (buf[i+2] != '!' && buf[i+2] != '+') { i = i + 2 multiLineComment = true continue diff --git a/ast/token_test.go b/ast/token_test.go index 939cd44857d3529e473b4ba7519f8ad9eaa0d00d..2c273d22048288e72d0e124c48d9cc957883a85b 100644 --- a/ast/token_test.go +++ b/ast/token_test.go @@ -166,6 +166,8 @@ select col from tb where col = 1;`), select col from tb; select col from tb; `), + []byte(`INSERT /*+ SET_VAR(foreign_key_checks=OFF) */ INTO t2 VALUES(2);`), + []byte(`select /*!50000 1,*/ 1;`), } buf2s := [][]byte{ []byte("select * from test\\Ghello"),