From 72a9ffc025ed9023bebe56d105b0d536bbdfa3ff Mon Sep 17 00:00:00 2001 From: Leon Zhang Date: Thu, 3 Jan 2019 21:45:14 +0800 Subject: [PATCH] splitstatement support optimizer hint https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html https://dev.mysql.com/doc/refman/8.0/en/comments.html --- ast/testdata/TestSplitStatement.golden | 2 ++ ast/token.go | 5 ++++- ast/token_test.go | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ast/testdata/TestSplitStatement.golden b/ast/testdata/TestSplitStatement.golden index a3e10ae..deb4590 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 3e14937..4267e83 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 939cd44..2c273d2 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"), -- GitLab