Skip to content

Commit 0c24bf7

Browse files
Scott Lanningbramp
authored andcommitted
support more index options to pass "create table" through vtexplain
USING was already supported, but I added COMMENT and KEY_BLOCK_SIZE. I didn't add WITH PARSER, though I guess that would be easy enough. IndexOption struct might be a little wrong. I ended up making "Using" a string, so that it wouldn't be quoted. (I tried to not append to an array, just fill in the struct, but was so far defeated by yacc.) In parse_test.go I did change the tests with "USING" to lowercase. I think that's okay. Signed-off-by: Scott Lanning <[email protected]>
1 parent f5b5a7f commit 0c24bf7

File tree

4 files changed

+2498
-2347
lines changed

4 files changed

+2498
-2347
lines changed

parse_test.go

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,12 +1713,22 @@ func TestCreateTable(t *testing.T) {
17131713
" email varchar,\n" +
17141714
" full_name varchar,\n" +
17151715
" status_nonkeyword varchar,\n" +
1716-
" primary key (id) USING BTREE,\n" +
1717-
" unique key by_username (username) USING HASH,\n" +
1718-
" unique by_username2 (username) USING OTHER,\n" +
1719-
" unique index by_username3 (username) USING XYZ,\n" +
1720-
" index by_status (status_nonkeyword) USING PDQ,\n" +
1721-
" key by_full_name (full_name) USING OTHER\n" +
1716+
" primary key (id) using BTREE,\n" +
1717+
" unique key by_username (username) using HASH,\n" +
1718+
" unique by_username2 (username) using OTHER,\n" +
1719+
" unique index by_username3 (username) using XYZ,\n" +
1720+
" index by_status (status_nonkeyword) using PDQ,\n" +
1721+
" key by_full_name (full_name) using OTHER\n" +
1722+
")",
1723+
// test other index options
1724+
"create table t (\n" +
1725+
" id int auto_increment,\n" +
1726+
" username varchar,\n" +
1727+
" email varchar,\n" +
1728+
" primary key (id) comment 'hi',\n" +
1729+
" unique key by_username (username) key_block_size 8,\n" +
1730+
" unique index by_username4 (username) comment 'hi' using BTREE,\n" +
1731+
" unique index by_username4 (username) using BTREE key_block_size 4 comment 'hi'\n" +
17221732
")",
17231733

17241734
// multi-column indexes
@@ -1790,6 +1800,38 @@ func TestCreateTable(t *testing.T) {
17901800
if tree != nil || err == nil {
17911801
t.Errorf("ParseStrictDDL unexpectedly accepted input %s", sql)
17921802
}
1803+
1804+
testCases := []struct {
1805+
input string
1806+
output string
1807+
}{{
1808+
// test key_block_size
1809+
input: "create table t (\n" +
1810+
" id int auto_increment,\n" +
1811+
" username varchar,\n" +
1812+
" unique key by_username (username) key_block_size 8,\n" +
1813+
" unique key by_username2 (username) key_block_size=8,\n" +
1814+
" unique by_username3 (username) key_block_size = 4\n" +
1815+
")",
1816+
output: "create table t (\n" +
1817+
" id int auto_increment,\n" +
1818+
" username varchar,\n" +
1819+
" unique key by_username (username) key_block_size 8,\n" +
1820+
" unique key by_username2 (username) key_block_size 8,\n" +
1821+
" unique by_username3 (username) key_block_size 4\n" +
1822+
")",
1823+
},
1824+
}
1825+
for _, tcase := range testCases {
1826+
tree, err := ParseStrictDDL(tcase.input)
1827+
if err != nil {
1828+
t.Errorf("input: %s, err: %v", tcase.input, err)
1829+
continue
1830+
}
1831+
if got, want := String(tree.(*DDL)), tcase.output; got != want {
1832+
t.Errorf("Parse(%s):\n%s, want\n%s", tcase.input, got, want)
1833+
}
1834+
}
17931835
}
17941836

17951837
func TestCreateTableEscaped(t *testing.T) {

0 commit comments

Comments
 (0)