Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Slack sync upstream/2018 02 07 #71

Merged
merged 6 commits into from
Feb 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion go/vt/sqlparser/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ func Preview(sql string) int {
case "delete":
return StmtDelete
}
switch strings.ToLower(trimmed) {
// For the following statements it is not sufficient to rely
// on loweredFirstWord. This is because they are not statements
// in the grammar and we are relying on Preview to parse them.
// For instance, we don't want: "BEGIN JUNK" to be parsed
// as StmtBegin.
trimmedNoComments, _ := SplitTrailingComments(trimmed)
switch strings.ToLower(trimmedNoComments) {
case "begin", "start transaction":
return StmtBegin
case "commit":
Expand Down
4 changes: 4 additions & 0 deletions go/vt/sqlparser/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ func TestPreview(t *testing.T) {
{"\n\t begin ", StmtBegin},
{"... begin ", StmtUnknown},
{"begin ...", StmtUnknown},
{"begin /* ... */", StmtBegin},
{"begin /* ... *//*test*/", StmtBegin},
{"start transaction", StmtBegin},
{"commit", StmtCommit},
{"commit /*...*/", StmtCommit},
{"rollback", StmtRollback},
{"rollback /*...*/", StmtRollback},
{"create", StmtDDL},
{"alter", StmtDDL},
{"rename", StmtDDL},
Expand Down
4 changes: 4 additions & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ func (ct *ColumnType) WalkSubtree(visit Visit) error {
type IndexDefinition struct {
Info *IndexInfo
Columns []*IndexColumn
Using ColIdent
}

// Format formats the node.
Expand All @@ -998,6 +999,9 @@ func (idx *IndexDefinition) Format(buf *TrackedBuffer) {
}
}
buf.Myprintf(")")
if !idx.Using.IsEmpty() {
buf.Myprintf(" USING %v", idx.Using)
}
}

// WalkSubtree walks the nodes of the subtree.
Expand Down
15 changes: 15 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,21 @@ func TestCreateTable(t *testing.T) {
" key by_full_name (full_name)\n" +
")",

// test that indexes support USING <id>
"create table t (\n" +
" id int auto_increment,\n" +
" username varchar,\n" +
" email varchar,\n" +
" full_name varchar,\n" +
" status_nonkeyword varchar,\n" +
" primary key (id) USING BTREE,\n" +
" unique key by_username (username) USING HASH,\n" +
" unique by_username2 (username) USING OTHER,\n" +
" unique index by_username3 (username) USING XYZ,\n" +
" index by_status (status_nonkeyword) USING PDQ,\n" +
" key by_full_name (full_name) USING OTHER\n" +
")",

// multi-column indexes
"create table t (\n" +
" id int auto_increment,\n" +
Expand Down
Loading