Skip to content

Commit 28709ba

Browse files
zhyassbohutang
authored andcommitted
* : complete create index syntax support #592
[summary] 1. create index syntax. CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name ON tbl_name (key_part,...) [index_option] [algorithm_option | lock_option] ... key_part: col_name [(length)] index_option: KEY_BLOCK_SIZE [=] value | index_type | WITH PARSER NGRAM | COMMENT 'string' index_type: USING {BTREE | HASH} algorithm_option: ALGORITHM [=] {DEFAULT | INPLACE | COPY} lock_option: LOCK [=] {DEFAULT | NONE | SHARED | EXCLUSIVE} 2. create table index definition syntax. index_definition: PRIMARY KEY (key_part,...) | UNIQUE [index_or_key] index_name (key_part,...) [index_option] | index_or_key index_name (key_part,...) [index_option] | FULLTEXT index_or_key index_name (key_part,...) [index_option] | SPATIAL index_or_key index_name (key_part,...) [index_option] index_or_key: INDEX | KEY [test case] src/planner/ddl_plan_test.go src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/ddl_test.go src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/parse_test.go [patch codecov] src/planner/ddl_plan.go 93.8% src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/ast.go 86.4%
1 parent f024ec2 commit 28709ba

File tree

12 files changed

+3204
-2473
lines changed

12 files changed

+3204
-2473
lines changed

docs/radon_sql_support.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,28 @@ RadonDB only supports the `CREATE/DROP INDEX` syntax in order to simplify the in
463463

464464
`Syntax`
465465
```
466-
CREATE INDEX index_name ON table_name (index_col_name,...)
466+
CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name
467+
ON tbl_name (key_part,...)
468+
[index_option]
469+
[algorithm_option | lock_option] ...
470+
471+
key_part:
472+
col_name [(length)]
473+
474+
index_option:
475+
KEY_BLOCK_SIZE [=] value
476+
| index_type
477+
| WITH PARSER NGRAM
478+
| COMMENT 'string'
479+
480+
index_type:
481+
USING {BTREE | HASH}
482+
483+
algorithm_option:
484+
ALGORITHM [=] {DEFAULT | INPLACE | COPY}
485+
486+
lock_option:
487+
LOCK [=] {DEFAULT | NONE | SHARED | EXCLUSIVE}
467488
```
468489

469490
`Instructions`

intergration/radon-test/r/ddl.result

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,38 @@ t CREATE TABLE `t` (\n `a` int(11) NOT NULL,\n `b` int(11) NOT NULL,\n `c` ch
2525
drop table integrate_test.t;
2626

2727

28+
create table integrate_test.t(
29+
a int,
30+
b int,
31+
c char(10),
32+
unique key a_idx(a) using btree comment 'unique',
33+
fulltext index c_idx(c) KEY_BLOCK_SIZE=10 WITH PARSER ngram
34+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
35+
36+
show create table integrate_test.t;
37+
Table Create Table
38+
t CREATE TABLE `t` (\n `a` int(11) DEFAULT NULL,\n `b` int(11) DEFAULT NULL,\n `c` char(10) DEFAULT NULL,\n UNIQUE KEY `a_idx` (`a`) USING BTREE COMMENT 'unique',\n FULLTEXT KEY `c_idx` (`c`) KEY_BLOCK_SIZE=10 /*!50100 WITH PARSER `ngram` */ \n) ENGINE=InnoDB DEFAULT CHARSET=utf8\n/*!50100 PARTITION BY HASH(a) */
39+
40+
drop table integrate_test.t;
41+
42+
43+
create table integrate_test.t(
44+
a int,
45+
b int,
46+
c char(10)
47+
) PARTITION BY HASH(a) ENGINE=InnoDB DEFAULT CHARSET=utf8;
48+
49+
create unique index a_idx on integrate_test.t(a);
50+
51+
create index b_idx on integrate_test.t(b) using btree KEY_BLOCK_SIZE=10 LOCK=DEFAULT ALGORITHM=COPY;
52+
53+
create FULLTEXT index c_idx on integrate_test.t(c) WITH PARSER ngram comment 'fulltext' ALGORITHM=DEFAULT LOCK=SHARED;
54+
55+
show create table integrate_test.t;
56+
Table Create Table
57+
t CREATE TABLE `t` (\n `a` int(11) DEFAULT NULL,\n `b` int(11) DEFAULT NULL,\n `c` char(10) DEFAULT NULL,\n UNIQUE KEY `a_idx` (`a`),\n KEY `b_idx` (`b`) USING BTREE KEY_BLOCK_SIZE=10,\n FULLTEXT KEY `c_idx` (`c`) COMMENT 'fulltext' /*!50100 WITH PARSER `ngram` */ \n) ENGINE=InnoDB DEFAULT CHARSET=utf8\n/*!50100 PARTITION BY HASH(a) */
58+
59+
drop table integrate_test.t;
60+
61+
2862
drop database integrate_test;

intergration/radon-test/t/ddl.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,25 @@ create table integrate_test.t(
1414
show create table integrate_test.t;
1515
drop table integrate_test.t;
1616

17+
create table integrate_test.t(
18+
a int,
19+
b int,
20+
c char(10),
21+
unique key a_idx(a) using btree comment 'unique',
22+
fulltext index c_idx(c) KEY_BLOCK_SIZE=10 WITH PARSER ngram
23+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
24+
show create table integrate_test.t;
25+
drop table integrate_test.t;
26+
27+
create table integrate_test.t(
28+
a int,
29+
b int,
30+
c char(10)
31+
) PARTITION BY HASH(a) ENGINE=InnoDB DEFAULT CHARSET=utf8;
32+
create unique index a_idx on integrate_test.t(a);
33+
create index b_idx on integrate_test.t(b) using btree KEY_BLOCK_SIZE=10 LOCK=DEFAULT ALGORITHM=COPY;
34+
create FULLTEXT index c_idx on integrate_test.t(c) WITH PARSER ngram comment 'fulltext' ALGORITHM=DEFAULT LOCK=SHARED;
35+
show create table integrate_test.t;
36+
drop table integrate_test.t;
37+
1738
drop database integrate_test;

src/planner/ddl_plan.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ func (p *DDLPlan) checkUnsupportedOperations(database, table string) error {
101101
}
102102
// constraint check in index definition
103103
for _, index := range node.TableSpec.Indexes {
104-
info := index.Info
105-
if info.Unique || info.Primary {
104+
if index.Unique || index.Primary {
106105
err := fmt.Sprintf("The unique/primary constraint should be only defined on the sharding key column[%s]", shardKey)
107106
return errors.New(err)
108107
}

src/planner/ddl_plan_test.go

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestDDLPlan1(t *testing.T) {
2424
"{\n\t\"RawQuery\": \"create table G(a int)\",\n\t\"Partitions\": [\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.G (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend1\",\n\t\t\t\"Range\": \"\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.G (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend2\",\n\t\t\t\"Range\": \"\"\n\t\t}\n\t]\n}",
2525
"{\n\t\"RawQuery\": \"create table S(a int)\",\n\t\"Partitions\": [\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.S (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend1\",\n\t\t\t\"Range\": \"\"\n\t\t}\n\t]\n}",
2626
"{\n\t\"RawQuery\": \"alter table A engine = tokudb\",\n\t\"Partitions\": [\n\t\t{\n\t\t\t\"Query\": \"alter table sbtest.A0 engine = tokudb\",\n\t\t\t\"Backend\": \"backend0\",\n\t\t\t\"Range\": \"[0-2)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"alter table sbtest.A2 engine = tokudb\",\n\t\t\t\"Backend\": \"backend2\",\n\t\t\t\"Range\": \"[2-4)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"alter table sbtest.A4 engine = tokudb\",\n\t\t\t\"Backend\": \"backend4\",\n\t\t\t\"Range\": \"[4-8)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"alter table sbtest.A8 engine = tokudb\",\n\t\t\t\"Backend\": \"backend8\",\n\t\t\t\"Range\": \"[8-4096)\"\n\t\t}\n\t]\n}",
27-
"{\n\t\"RawQuery\": \"create index idx_a on A(a)\",\n\t\"Partitions\": [\n\t\t{\n\t\t\t\"Query\": \"create index idx_a on sbtest.A0\",\n\t\t\t\"Backend\": \"backend0\",\n\t\t\t\"Range\": \"[0-2)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create index idx_a on sbtest.A2\",\n\t\t\t\"Backend\": \"backend2\",\n\t\t\t\"Range\": \"[2-4)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create index idx_a on sbtest.A4\",\n\t\t\t\"Backend\": \"backend4\",\n\t\t\t\"Range\": \"[4-8)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create index idx_a on sbtest.A8\",\n\t\t\t\"Backend\": \"backend8\",\n\t\t\t\"Range\": \"[8-4096)\"\n\t\t}\n\t]\n}",
27+
"{\n\t\"RawQuery\": \"create index idx_a on A(a)\",\n\t\"Partitions\": [\n\t\t{\n\t\t\t\"Query\": \"create index idx_a on sbtest.A0(`a`)\",\n\t\t\t\"Backend\": \"backend0\",\n\t\t\t\"Range\": \"[0-2)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create index idx_a on sbtest.A2(`a`)\",\n\t\t\t\"Backend\": \"backend2\",\n\t\t\t\"Range\": \"[2-4)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create index idx_a on sbtest.A4(`a`)\",\n\t\t\t\"Backend\": \"backend4\",\n\t\t\t\"Range\": \"[4-8)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create index idx_a on sbtest.A8(`a`)\",\n\t\t\t\"Backend\": \"backend8\",\n\t\t\t\"Range\": \"[8-4096)\"\n\t\t}\n\t]\n}",
2828
"{\n\t\"RawQuery\": \"drop index idx_a on sbtest.A\",\n\t\"Partitions\": [\n\t\t{\n\t\t\t\"Query\": \"drop index idx_a on sbtest.A0\",\n\t\t\t\"Backend\": \"backend0\",\n\t\t\t\"Range\": \"[0-2)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"drop index idx_a on sbtest.A2\",\n\t\t\t\"Backend\": \"backend2\",\n\t\t\t\"Range\": \"[2-4)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"drop index idx_a on sbtest.A4\",\n\t\t\t\"Backend\": \"backend4\",\n\t\t\t\"Range\": \"[4-8)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"drop index idx_a on sbtest.A8\",\n\t\t\t\"Backend\": \"backend8\",\n\t\t\t\"Range\": \"[8-4096)\"\n\t\t}\n\t]\n}",
2929
"{\n\t\"RawQuery\": \"alter table A add column(b int)\",\n\t\"Partitions\": [\n\t\t{\n\t\t\t\"Query\": \"alter table sbtest.A0 add column (\\n\\t`b` int\\n)\",\n\t\t\t\"Backend\": \"backend0\",\n\t\t\t\"Range\": \"[0-2)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"alter table sbtest.A2 add column (\\n\\t`b` int\\n)\",\n\t\t\t\"Backend\": \"backend2\",\n\t\t\t\"Range\": \"[2-4)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"alter table sbtest.A4 add column (\\n\\t`b` int\\n)\",\n\t\t\t\"Backend\": \"backend4\",\n\t\t\t\"Range\": \"[4-8)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"alter table sbtest.A8 add column (\\n\\t`b` int\\n)\",\n\t\t\t\"Backend\": \"backend8\",\n\t\t\t\"Range\": \"[8-4096)\"\n\t\t}\n\t]\n}",
3030
"{\n\t\"RawQuery\": \"alter table sbtest.A add column(b int)\",\n\t\"Partitions\": [\n\t\t{\n\t\t\t\"Query\": \"alter table sbtest.A0 add column (\\n\\t`b` int\\n)\",\n\t\t\t\"Backend\": \"backend0\",\n\t\t\t\"Range\": \"[0-2)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"alter table sbtest.A2 add column (\\n\\t`b` int\\n)\",\n\t\t\t\"Backend\": \"backend2\",\n\t\t\t\"Range\": \"[2-4)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"alter table sbtest.A4 add column (\\n\\t`b` int\\n)\",\n\t\t\t\"Backend\": \"backend4\",\n\t\t\t\"Range\": \"[4-8)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"alter table sbtest.A8 add column (\\n\\t`b` int\\n)\",\n\t\t\t\"Backend\": \"backend8\",\n\t\t\t\"Range\": \"[8-4096)\"\n\t\t}\n\t]\n}",
@@ -202,13 +202,117 @@ func TestDDLAlterError(t *testing.T) {
202202
}
203203
}
204204

205-
func TestDDLPlanCreateIndexWithTableNameIssue10(t *testing.T) {
205+
func TestDDLPlanCreateIndex(t *testing.T) {
206206
results := []string{
207-
"{\n\t\"RawQuery\": \"create index idx_A_id on A(a)\",\n\t\"Partitions\": [\n\t\t{\n\t\t\t\"Query\": \"create index idx_A_id on sbtest.A0\",\n\t\t\t\"Backend\": \"backend0\",\n\t\t\t\"Range\": \"[0-2)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create index idx_A_id on sbtest.A2\",\n\t\t\t\"Backend\": \"backend2\",\n\t\t\t\"Range\": \"[2-4)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create index idx_A_id on sbtest.A4\",\n\t\t\t\"Backend\": \"backend4\",\n\t\t\t\"Range\": \"[4-8)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create index idx_A_id on sbtest.A8\",\n\t\t\t\"Backend\": \"backend8\",\n\t\t\t\"Range\": \"[8-4096)\"\n\t\t}\n\t]\n}",
207+
`{
208+
"RawQuery": "create index idx_A_id on A(a)",
209+
"Partitions": [
210+
{
211+
"Query": "create index idx_A_id on sbtest.A0(` + "`a`" + `)",
212+
"Backend": "backend0",
213+
"Range": "[0-2)"
214+
},
215+
{
216+
"Query": "create index idx_A_id on sbtest.A2(` + "`a`" + `)",
217+
"Backend": "backend2",
218+
"Range": "[2-4)"
219+
},
220+
{
221+
"Query": "create index idx_A_id on sbtest.A4(` + "`a`" + `)",
222+
"Backend": "backend4",
223+
"Range": "[4-8)"
224+
},
225+
{
226+
"Query": "create index idx_A_id on sbtest.A8(` + "`a`" + `)",
227+
"Backend": "backend8",
228+
"Range": "[8-4096)"
229+
}
230+
]
231+
}`,
232+
`{
233+
"RawQuery": "create fulltext index idx on A(a) with parser ngram lock=none algorithm=copy",
234+
"Partitions": [
235+
{
236+
"Query": "create fulltext index idx on sbtest.A0(` + "`a`" + `) WITH PARSER ngram algorithm = copy lock = none",
237+
"Backend": "backend0",
238+
"Range": "[0-2)"
239+
},
240+
{
241+
"Query": "create fulltext index idx on sbtest.A2(` + "`a`" + `) WITH PARSER ngram algorithm = copy lock = none",
242+
"Backend": "backend2",
243+
"Range": "[2-4)"
244+
},
245+
{
246+
"Query": "create fulltext index idx on sbtest.A4(` + "`a`" + `) WITH PARSER ngram algorithm = copy lock = none",
247+
"Backend": "backend4",
248+
"Range": "[4-8)"
249+
},
250+
{
251+
"Query": "create fulltext index idx on sbtest.A8(` + "`a`" + `) WITH PARSER ngram algorithm = copy lock = none",
252+
"Backend": "backend8",
253+
"Range": "[8-4096)"
254+
}
255+
]
256+
}`,
257+
`{
258+
"RawQuery": "create index idx on A(a) using hash comment 'c' lock=shared",
259+
"Partitions": [
260+
{
261+
"Query": "create index idx on sbtest.A0(` + "`a`" + `) using hash comment 'c' lock = shared",
262+
"Backend": "backend0",
263+
"Range": "[0-2)"
264+
},
265+
{
266+
"Query": "create index idx on sbtest.A2(` + "`a`" + `) using hash comment 'c' lock = shared",
267+
"Backend": "backend2",
268+
"Range": "[2-4)"
269+
},
270+
{
271+
"Query": "create index idx on sbtest.A4(` + "`a`" + `) using hash comment 'c' lock = shared",
272+
"Backend": "backend4",
273+
"Range": "[4-8)"
274+
},
275+
{
276+
"Query": "create index idx on sbtest.A8(` + "`a`" + `) using hash comment 'c' lock = shared",
277+
"Backend": "backend8",
278+
"Range": "[8-4096)"
279+
}
280+
]
281+
}`,
282+
`{
283+
"RawQuery": "create spatial index idx on A(gis) key_block_size=10 algorithm=default",
284+
"Partitions": [
285+
{
286+
"Query": "create spatial index idx on sbtest.A0(` + "`gis`" + `) key_block_size = 10 algorithm = default",
287+
"Backend": "backend0",
288+
"Range": "[0-2)"
289+
},
290+
{
291+
"Query": "create spatial index idx on sbtest.A2(` + "`gis`" + `) key_block_size = 10 algorithm = default",
292+
"Backend": "backend2",
293+
"Range": "[2-4)"
294+
},
295+
{
296+
"Query": "create spatial index idx on sbtest.A4(` + "`gis`" + `) key_block_size = 10 algorithm = default",
297+
"Backend": "backend4",
298+
"Range": "[4-8)"
299+
},
300+
{
301+
"Query": "create spatial index idx on sbtest.A8(` + "`gis`" + `) key_block_size = 10 algorithm = default",
302+
"Backend": "backend8",
303+
"Range": "[8-4096)"
304+
}
305+
]
306+
}`,
208307
}
209308

210309
querys := []string{
310+
// issue 10.
211311
"create index idx_A_id on A(a)",
312+
// issue 592.
313+
"create fulltext index idx on A(a) with parser ngram lock=none algorithm=copy",
314+
"create index idx on A(a) using hash comment 'c' lock=shared",
315+
"create spatial index idx on A(gis) key_block_size=10 algorithm=default",
212316
}
213317

214318
log := xlog.NewStdLog(xlog.Level(xlog.PANIC))
@@ -252,6 +356,8 @@ func TestDDLPlanWithQuote(t *testing.T) {
252356
"{\n\t\"RawQuery\": \"create table sbtest.A (\\n\\t`a` int\\n)\",\n\t\"Partitions\": [\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.A0 (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend0\",\n\t\t\t\"Range\": \"[0-2)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.A2 (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend2\",\n\t\t\t\"Range\": \"[2-4)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.A4 (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend4\",\n\t\t\t\"Range\": \"[4-8)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.A8 (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend8\",\n\t\t\t\"Range\": \"[8-4096)\"\n\t\t}\n\t]\n}",
253357
"{\n\t\"RawQuery\": \"create table sbtest.A (\\n\\t`a` int\\n)\",\n\t\"Partitions\": [\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.A0 (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend0\",\n\t\t\t\"Range\": \"[0-2)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.A2 (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend2\",\n\t\t\t\"Range\": \"[2-4)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.A4 (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend4\",\n\t\t\t\"Range\": \"[4-8)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.A8 (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend8\",\n\t\t\t\"Range\": \"[8-4096)\"\n\t\t}\n\t]\n}",
254358
"{\n\t\"RawQuery\": \"create table sbtest.A (\\n\\t`a` int\\n)\",\n\t\"Partitions\": [\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.A0 (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend0\",\n\t\t\t\"Range\": \"[0-2)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.A2 (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend2\",\n\t\t\t\"Range\": \"[2-4)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.A4 (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend4\",\n\t\t\t\"Range\": \"[4-8)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.A8 (\\n\\t`a` int\\n)\",\n\t\t\t\"Backend\": \"backend8\",\n\t\t\t\"Range\": \"[8-4096)\"\n\t\t}\n\t]\n}",
359+
"{\n\t\"RawQuery\": \"create table B (\\n\\t`a` int,\\n\\t`b` varchar(10),\\n\\tunique key `a_idx` (`a`) using btree comment 'key'\\n)\",\n\t\"Partitions\": [\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.B0 (\\n\\t`a` int,\\n\\t`b` varchar(10),\\n\\tunique key `a_idx` (`a`) using btree comment 'key'\\n)\",\n\t\t\t\"Backend\": \"backend1\",\n\t\t\t\"Range\": \"[0-512)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.B1 (\\n\\t`a` int,\\n\\t`b` varchar(10),\\n\\tunique key `a_idx` (`a`) using btree comment 'key'\\n)\",\n\t\t\t\"Backend\": \"backend2\",\n\t\t\t\"Range\": \"[512-4096)\"\n\t\t}\n\t]\n}",
360+
"{\n\t\"RawQuery\": \"create table B (\\n\\t`b` varchar(10),\\n\\tfulltext index `b_idx` (`b`) key_block_size = 10 WITH PARSER ngram\\n)\",\n\t\"Partitions\": [\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.B0 (\\n\\t`b` varchar(10),\\n\\tfulltext index `b_idx` (`b`) key_block_size = 10 WITH PARSER ngram\\n)\",\n\t\t\t\"Backend\": \"backend1\",\n\t\t\t\"Range\": \"[0-512)\"\n\t\t},\n\t\t{\n\t\t\t\"Query\": \"create table sbtest.B1 (\\n\\t`b` varchar(10),\\n\\tfulltext index `b_idx` (`b`) key_block_size = 10 WITH PARSER ngram\\n)\",\n\t\t\t\"Backend\": \"backend2\",\n\t\t\t\"Range\": \"[512-4096)\"\n\t\t}\n\t]\n}",
255361
}
256362

257363
querys := []string{
@@ -262,6 +368,8 @@ func TestDDLPlanWithQuote(t *testing.T) {
262368
"create table sbtest.`A`(a int)",
263369
"create table `sbtest`.A(a int)",
264370
"create table `sbtest`.`A`(a int)",
371+
"create table B(a int, b varchar(10), unique key a_idx(a) using btree comment 'key')",
372+
"create table B(b varchar(10), fulltext index b_idx(b) with parser ngram key_block_size=10)",
265373
}
266374

267375
log := xlog.NewStdLog(xlog.Level(xlog.PANIC))
@@ -270,7 +378,7 @@ func TestDDLPlanWithQuote(t *testing.T) {
270378
route, cleanup := router.MockNewRouter(log)
271379
defer cleanup()
272380

273-
err := route.AddForTest(database, router.MockTableAConfig())
381+
err := route.AddForTest(database, router.MockTableAConfig(), router.MockTableBConfig())
274382
assert.Nil(t, err)
275383
for i, query := range querys {
276384
log.Debug("%v", query)

src/proxy/ddl.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ func tryGetShardKey(ddl *sqlparser.DDL) (string, error) {
7878
// constraint check in index definition
7979
for _, index := range ddl.TableSpec.Indexes {
8080
constraintCheckOK = false
81-
info := index.Info
82-
if info.Unique || info.Primary {
83-
for _, colIdx := range index.Columns {
81+
if index.Unique || index.Primary {
82+
for _, colIdx := range index.Opts.Columns {
8483
colName := colIdx.Column.String()
8584
if colName == shardKey {
8685
constraintCheckOK = true
@@ -103,10 +102,9 @@ func tryGetShardKey(ddl *sqlparser.DDL) (string, error) {
103102
}
104103
// constraint check in index definition.
105104
for _, index := range ddl.TableSpec.Indexes {
106-
info := index.Info
107-
if info.Unique || info.Primary {
108-
if len(index.Columns) == 1 {
109-
return index.Columns[0].Column.String(), nil
105+
if index.Unique || index.Primary {
106+
if len(index.Opts.Columns) == 1 {
107+
return index.Opts.Columns[0].Column.String(), nil
110108
}
111109
}
112110
}

0 commit comments

Comments
 (0)