Support USING method when creating indexes. (#731)

* fix: create index using function

* fix: code style

Co-authored-by: yangjiaxin <yangjiaxin@qianxin.com>
This commit is contained in:
mao 2022-12-01 02:17:38 +08:00 committed by GitHub
parent 7101e0021f
commit 316359760d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 9 deletions

View file

@ -5162,6 +5162,7 @@ fn parse_create_index() {
columns,
unique,
if_not_exists,
..
} => {
assert_eq!("idx_name", name.to_string());
assert_eq!("test", table_name.to_string());
@ -5173,6 +5174,41 @@ fn parse_create_index() {
}
}
#[test]
fn test_create_index_with_using_function() {
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test USING btree (name,age DESC)";
let indexed_columns = vec![
OrderByExpr {
expr: Expr::Identifier(Ident::new("name")),
asc: None,
nulls_first: None,
},
OrderByExpr {
expr: Expr::Identifier(Ident::new("age")),
asc: Some(false),
nulls_first: None,
},
];
match verified_stmt(sql) {
Statement::CreateIndex {
name,
table_name,
using,
columns,
unique,
if_not_exists,
} => {
assert_eq!("idx_name", name.to_string());
assert_eq!("test", table_name.to_string());
assert_eq!("btree", using.unwrap().to_string());
assert_eq!(indexed_columns, columns);
assert!(unique);
assert!(if_not_exists)
}
_ => unreachable!(),
}
}
#[test]
fn parse_drop_index() {
let sql = "DROP INDEX idx_a";