Skip to content

Commit ab8e6ad

Browse files
amaksimoiffyio
andauthored
Add ASYNC keyword support for CREATE INDEX (apache#2302)
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
1 parent 7c78d13 commit ab8e6ad

6 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/ast/ddl.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2817,6 +2817,10 @@ pub struct CreateIndex {
28172817
pub unique: bool,
28182818
/// whether the index is created concurrently
28192819
pub concurrently: bool,
2820+
/// whether the index is created asynchronously ([DSQL]).
2821+
///
2822+
/// [DSQL]: https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-create-index-async.html
2823+
pub r#async: bool,
28202824
/// IF NOT EXISTS clause
28212825
pub if_not_exists: bool,
28222826
/// INCLUDE clause: <https://www.postgresql.org/docs/current/sql-createindex.html>
@@ -2842,13 +2846,14 @@ impl fmt::Display for CreateIndex {
28422846
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
28432847
write!(
28442848
f,
2845-
"CREATE {unique}INDEX {concurrently}{if_not_exists}",
2849+
"CREATE {unique}INDEX {concurrently}{async_}{if_not_exists}",
28462850
unique = if self.unique { "UNIQUE " } else { "" },
28472851
concurrently = if self.concurrently {
28482852
"CONCURRENTLY "
28492853
} else {
28502854
""
28512855
},
2856+
async_ = if self.r#async { "ASYNC " } else { "" },
28522857
if_not_exists = if self.if_not_exists {
28532858
"IF NOT EXISTS "
28542859
} else {

src/ast/spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ impl Spanned for CreateIndex {
694694
columns,
695695
unique: _, // bool
696696
concurrently: _, // bool
697+
r#async: _, // bool
697698
if_not_exists: _, // bool
698699
include,
699700
nulls_distinct: _, // bool

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ define_keywords!(
131131
ASOF,
132132
ASSERT,
133133
ASYMMETRIC,
134+
ASYNC,
134135
AT,
135136
ATOMIC,
136137
ATTACH,

src/parser/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8043,6 +8043,7 @@ impl<'a> Parser<'a> {
80438043
/// Parse a `CREATE INDEX` statement.
80448044
pub fn parse_create_index(&mut self, unique: bool) -> Result<CreateIndex, ParserError> {
80458045
let concurrently = self.parse_keyword(Keyword::CONCURRENTLY);
8046+
let r#async = self.parse_keyword(Keyword::ASYNC);
80468047
let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
80478048

80488049
let mut using = None;
@@ -8122,6 +8123,7 @@ impl<'a> Parser<'a> {
81228123
columns,
81238124
unique,
81248125
concurrently,
8126+
r#async,
81258127
if_not_exists,
81268128
include,
81278129
nulls_distinct,

tests/sqlparser_common.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9626,6 +9626,7 @@ fn test_create_index_with_using_function() {
96269626
columns,
96279627
unique,
96289628
concurrently,
9629+
r#async,
96299630
if_not_exists,
96309631
include,
96319632
nulls_distinct: None,
@@ -9640,6 +9641,7 @@ fn test_create_index_with_using_function() {
96409641
assert_eq!(indexed_columns, columns);
96419642
assert!(unique);
96429643
assert!(!concurrently);
9644+
assert!(!r#async);
96439645
assert!(if_not_exists);
96449646
assert!(include.is_empty());
96459647
assert!(with.is_empty());
@@ -9681,6 +9683,7 @@ fn test_create_index_with_with_clause() {
96819683
columns,
96829684
unique,
96839685
concurrently,
9686+
r#async,
96849687
if_not_exists,
96859688
include,
96869689
nulls_distinct: None,
@@ -9694,6 +9697,7 @@ fn test_create_index_with_with_clause() {
96949697
pretty_assertions::assert_eq!(indexed_columns, columns);
96959698
assert!(unique);
96969699
assert!(!concurrently);
9700+
assert!(!r#async);
96979701
assert!(!if_not_exists);
96989702
assert!(include.is_empty());
96999703
pretty_assertions::assert_eq!(with_parameters, with);
@@ -9704,6 +9708,12 @@ fn test_create_index_with_with_clause() {
97049708
}
97059709
}
97069710

9711+
#[test]
9712+
fn parse_create_index_async() {
9713+
verified_stmt("CREATE INDEX ASYNC my_index ON my_table(col1)");
9714+
verified_stmt("CREATE UNIQUE INDEX ASYNC my_index ON my_table(col1)");
9715+
}
9716+
97079717
#[test]
97089718
fn parse_drop_index() {
97099719
let sql = "DROP INDEX idx_a";

tests/sqlparser_postgres.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,6 +2806,7 @@ fn parse_create_index() {
28062806
columns,
28072807
unique,
28082808
concurrently,
2809+
r#async,
28092810
if_not_exists,
28102811
nulls_distinct: None,
28112812
include,
@@ -2819,6 +2820,7 @@ fn parse_create_index() {
28192820
assert_eq!(None, using);
28202821
assert!(!unique);
28212822
assert!(!concurrently);
2823+
assert!(!r#async);
28222824
assert!(if_not_exists);
28232825
assert_eq_vec(&["col1", "col2"], &columns);
28242826
assert!(include.is_empty());
@@ -2841,6 +2843,7 @@ fn parse_create_anonymous_index() {
28412843
columns,
28422844
unique,
28432845
concurrently,
2846+
r#async,
28442847
if_not_exists,
28452848
include,
28462849
nulls_distinct: None,
@@ -2854,6 +2857,7 @@ fn parse_create_anonymous_index() {
28542857
assert_eq!(None, using);
28552858
assert!(!unique);
28562859
assert!(!concurrently);
2860+
assert!(!r#async);
28572861
assert!(!if_not_exists);
28582862
assert_eq_vec(&["col1", "col2"], &columns);
28592863
assert!(include.is_empty());
@@ -2959,6 +2963,7 @@ fn parse_create_indices_with_operator_classes() {
29592963
columns,
29602964
unique: false,
29612965
concurrently: false,
2966+
r#async: false,
29622967
if_not_exists: false,
29632968
include,
29642969
nulls_distinct: None,
@@ -2987,6 +2992,7 @@ fn parse_create_indices_with_operator_classes() {
29872992
columns,
29882993
unique: false,
29892994
concurrently: false,
2995+
r#async: false,
29902996
if_not_exists: false,
29912997
include,
29922998
nulls_distinct: None,
@@ -3070,6 +3076,7 @@ fn parse_create_bloom() {
30703076
columns,
30713077
unique: false,
30723078
concurrently: false,
3079+
r#async: false,
30733080
if_not_exists: false,
30743081
include,
30753082
nulls_distinct: None,
@@ -3126,6 +3133,7 @@ fn parse_create_brin() {
31263133
columns,
31273134
unique: false,
31283135
concurrently: false,
3136+
r#async: false,
31293137
if_not_exists: false,
31303138
include,
31313139
nulls_distinct: None,
@@ -3193,6 +3201,7 @@ fn parse_create_index_concurrently() {
31933201
columns,
31943202
unique,
31953203
concurrently,
3204+
r#async,
31963205
if_not_exists,
31973206
include,
31983207
nulls_distinct: None,
@@ -3206,6 +3215,7 @@ fn parse_create_index_concurrently() {
32063215
assert_eq!(None, using);
32073216
assert!(!unique);
32083217
assert!(concurrently);
3218+
assert!(!r#async);
32093219
assert!(if_not_exists);
32103220
assert_eq_vec(&["col1", "col2"], &columns);
32113221
assert!(include.is_empty());
@@ -3228,6 +3238,7 @@ fn parse_create_index_with_predicate() {
32283238
columns,
32293239
unique,
32303240
concurrently,
3241+
r#async,
32313242
if_not_exists,
32323243
include,
32333244
nulls_distinct: None,
@@ -3241,6 +3252,7 @@ fn parse_create_index_with_predicate() {
32413252
assert_eq!(None, using);
32423253
assert!(!unique);
32433254
assert!(!concurrently);
3255+
assert!(!r#async);
32443256
assert!(if_not_exists);
32453257
assert_eq_vec(&["col1", "col2"], &columns);
32463258
assert!(include.is_empty());
@@ -3263,6 +3275,7 @@ fn parse_create_index_with_include() {
32633275
columns,
32643276
unique,
32653277
concurrently,
3278+
r#async,
32663279
if_not_exists,
32673280
include,
32683281
nulls_distinct: None,
@@ -3276,6 +3289,7 @@ fn parse_create_index_with_include() {
32763289
assert_eq!(None, using);
32773290
assert!(!unique);
32783291
assert!(!concurrently);
3292+
assert!(!r#async);
32793293
assert!(if_not_exists);
32803294
assert_eq_vec(&["col1", "col2"], &columns);
32813295
assert_eq_vec(&["col3", "col4"], &include);
@@ -3298,6 +3312,7 @@ fn parse_create_index_with_nulls_distinct() {
32983312
columns,
32993313
unique,
33003314
concurrently,
3315+
r#async,
33013316
if_not_exists,
33023317
include,
33033318
nulls_distinct: Some(nulls_distinct),
@@ -3311,6 +3326,7 @@ fn parse_create_index_with_nulls_distinct() {
33113326
assert_eq!(None, using);
33123327
assert!(!unique);
33133328
assert!(!concurrently);
3329+
assert!(!r#async);
33143330
assert!(if_not_exists);
33153331
assert_eq_vec(&["col1", "col2"], &columns);
33163332
assert!(include.is_empty());
@@ -3331,6 +3347,7 @@ fn parse_create_index_with_nulls_distinct() {
33313347
columns,
33323348
unique,
33333349
concurrently,
3350+
r#async,
33343351
if_not_exists,
33353352
include,
33363353
nulls_distinct: Some(nulls_distinct),
@@ -3344,6 +3361,7 @@ fn parse_create_index_with_nulls_distinct() {
33443361
assert_eq!(None, using);
33453362
assert!(!unique);
33463363
assert!(!concurrently);
3364+
assert!(!r#async);
33473365
assert!(if_not_exists);
33483366
assert_eq_vec(&["col1", "col2"], &columns);
33493367
assert!(include.is_empty());

0 commit comments

Comments
 (0)