Adding MySQL table option {INDEX | KEY} to the CREATE TABLE definiton (partial). (#665)

Theoretically the behavior should be the same as CREATE INDEX, but we
cannot make that assumption, so the parse is (almost) identical as the
input.

Breaking changes:
- Now HASH and BTREE are KEYWORDS, and using them as names can result in
  errors.
- Now 'KEY' and 'INDEX' column names start the parsing of a table constraint if unquoted for the Generic dialect. This results in possible conficts if canonical results are compared for all dialects if a column is named 'key' without quotes.
This commit is contained in:
AugustoFKL 2022-10-19 18:24:38 -03:00 committed by GitHub
parent e3c936a6ce
commit 2aba3f8c91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 242 additions and 5 deletions

View file

@ -1073,6 +1073,49 @@ fn parse_limit_my_sql_syntax() {
);
}
#[test]
fn parse_create_table_with_index_definition() {
mysql_and_generic().one_statement_parses_to(
"CREATE TABLE tb (id INT, INDEX (id))",
"CREATE TABLE tb (id INT, INDEX (id))",
);
mysql_and_generic().one_statement_parses_to(
"CREATE TABLE tb (id INT, index USING BTREE (id))",
"CREATE TABLE tb (id INT, INDEX USING BTREE (id))",
);
mysql_and_generic().one_statement_parses_to(
"CREATE TABLE tb (id INT, KEY USING HASH (id))",
"CREATE TABLE tb (id INT, KEY USING HASH (id))",
);
mysql_and_generic().one_statement_parses_to(
"CREATE TABLE tb (id INT, key index (id))",
"CREATE TABLE tb (id INT, KEY index (id))",
);
mysql_and_generic().one_statement_parses_to(
"CREATE TABLE tb (id INT, INDEX 'index' (id))",
"CREATE TABLE tb (id INT, INDEX 'index' (id))",
);
mysql_and_generic().one_statement_parses_to(
"CREATE TABLE tb (id INT, INDEX index USING BTREE (id))",
"CREATE TABLE tb (id INT, INDEX index USING BTREE (id))",
);
mysql_and_generic().one_statement_parses_to(
"CREATE TABLE tb (id INT, INDEX index USING HASH (id))",
"CREATE TABLE tb (id INT, INDEX index USING HASH (id))",
);
mysql_and_generic().one_statement_parses_to(
"CREATE TABLE tb (id INT, INDEX (c1, c2, c3, c4,c5))",
"CREATE TABLE tb (id INT, INDEX (c1, c2, c3, c4, c5))",
);
}
fn mysql() -> TestedDialects {
TestedDialects {
dialects: vec![Box::new(MySqlDialect {})],