Skip to content

Commit

Permalink
fix XiaoMi#178 and add optimizer hint in SplitStatement function (Xia…
Browse files Browse the repository at this point in the history
…oMi#179)

* fix XiaoMi#176

  JSON datatype only support utf8mb4 now

* 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

* vendor daily update
  • Loading branch information
martianzhang authored and LPX-E5BD8 committed Jan 3, 2019
1 parent b0509d0 commit d424298
Show file tree
Hide file tree
Showing 22 changed files with 1,714 additions and 1,432 deletions.
2 changes: 2 additions & 0 deletions ast/testdata/TestSplitStatement.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion ast/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions ast/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
3 changes: 3 additions & 0 deletions database/sampling.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ func (db *Connector) startSampling(onlineConn *sql.DB, database, table string, w
values = append(values, "NULL")
} else {
switch columnTypes[i].DatabaseTypeName() {
case "JSON":
// https://github.com/XiaoMi/soar/issues/178
values = append(values, fmt.Sprintf(`convert(X'%s' using utf8mb4)`, fmt.Sprintf("%x", val)))
case "TIMESTAMP", "DATETIME":
t, err := time.Parse(time.RFC3339, string(val))
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/pingcap/parser/ast/ast.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 48 additions & 9 deletions vendor/github.com/pingcap/parser/ast/dml.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vendor/github.com/pingcap/parser/ast/flag.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

138 changes: 135 additions & 3 deletions vendor/github.com/pingcap/parser/ast/functions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions vendor/github.com/pingcap/parser/ast/misc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d424298

Please sign in to comment.