Commit 9fc38bd
authored
fix(parser): support MySQL index options and prefix-length key parts in index DDL (#2505)
* fix(parser): support index key parts with a prefix length and a direction
MySQL allows a key part to carry both a prefix length and a sort direction,
e.g. "CREATE INDEX i ON t (c1(20) DESC)". IndexColumnWithParams() accepted at
most one optional CreateParameter() per key part, so the prefix length consumed
it and the following ASC/DESC could not be matched.
Collect the parameters in a loop instead. IndexColumnsWithParamsList() is shared
by the CREATE INDEX and the ALTER TABLE ADD INDEX paths, so both are fixed.
Refs #2490
* fix(parser): support MySQL index options in CREATE INDEX and DROP INDEX
Several valid MySQL index DDL statements were rejected because their option
keywords are tokens of their own and were therefore not reachable from the
option lists that CREATE INDEX and DROP INDEX use:
CREATE INDEX i ON t (c1) KEY_BLOCK_SIZE = 8
CREATE INDEX i ON t (c1) ALGORITHM = INPLACE LOCK = NONE
CREATE FULLTEXT INDEX i ON t (body) WITH PARSER ngram
CREATE SPATIAL INDEX i ON t (g)
DROP INDEX i ON t ALGORITHM = INPLACE LOCK = NONE
The keywords are added to the existing flat token lists of CreateParameter()
and Drop() rather than as new grammar alternatives, so no new choice is
introduced and the JavaCC warning count is unchanged.
LOCK is the one exception: it also starts a LOCK TABLE statement, so taking it
unconditionally as a DROP argument would be ambiguous with the next statement.
It is guarded by a semantic lookahead that only accepts it when it is not
followed by TABLE.
Refs #2490
* refactor(parser): clarify key part option variable names in IndexColumnWithParams
Rename the accumulator to columnParams and keep parameter for the result of a
single CreateParameter(), matching how the other CreateParameter() loops in the
grammar name them. Collect eagerly and pass null only when no option was parsed,
because ColumnParams renders a separating space for a non-null list.1 parent 4658415 commit 9fc38bd
4 files changed
Lines changed: 105 additions & 6 deletions
File tree
- src
- main/jjtree/net/sf/jsqlparser/parser
- test/java/net/sf/jsqlparser/statement
- alter
- create
- drop
Lines changed: 25 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10979 | 10979 | | |
10980 | 10980 | | |
10981 | 10981 | | |
| 10982 | + | |
| 10983 | + | |
10982 | 10984 | | |
10983 | 10985 | | |
10984 | 10986 | | |
10985 | 10987 | | |
10986 | 10988 | | |
10987 | 10989 | | |
10988 | 10990 | | |
10989 | | - | |
10990 | | - | |
| 10991 | + | |
| 10992 | + | |
| 10993 | + | |
10991 | 10994 | | |
10992 | | - | |
| 10995 | + | |
| 10996 | + | |
| 10997 | + | |
| 10998 | + | |
10993 | 10999 | | |
10994 | 11000 | | |
10995 | 11001 | | |
10996 | | - | |
10997 | | - | |
| 11002 | + | |
10998 | 11003 | | |
10999 | | - | |
| 11004 | + | |
| 11005 | + | |
11000 | 11006 | | |
11001 | 11007 | | |
11002 | 11008 | | |
| |||
11846 | 11852 | | |
11847 | 11853 | | |
11848 | 11854 | | |
| 11855 | + | |
| 11856 | + | |
| 11857 | + | |
| 11858 | + | |
| 11859 | + | |
11849 | 11860 | | |
11850 | 11861 | | |
11851 | 11862 | | |
| |||
12021 | 12032 | | |
12022 | 12033 | | |
12023 | 12034 | | |
| 12035 | + | |
| 12036 | + | |
| 12037 | + | |
12024 | 12038 | | |
12025 | 12039 | | |
12026 | 12040 | | |
12027 | 12041 | | |
12028 | 12042 | | |
| 12043 | + | |
| 12044 | + | |
| 12045 | + | |
| 12046 | + | |
| 12047 | + | |
12029 | 12048 | | |
12030 | 12049 | | |
12031 | 12050 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2406 | 2406 | | |
2407 | 2407 | | |
2408 | 2408 | | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
2409 | 2417 | | |
Lines changed: 55 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
182 | 237 | | |
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
152 | 154 | | |
153 | 155 | | |
154 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
155 | 172 | | |
0 commit comments