Skip to content

Add ASYNC keyword support for CREATE INDEX#2302

Open
amaksimo wants to merge 1 commit intoapache:mainfrom
amaksimo:dsql-async-index
Open

Add ASYNC keyword support for CREATE INDEX#2302
amaksimo wants to merge 1 commit intoapache:mainfrom
amaksimo:dsql-async-index

Conversation

@amaksimo
Copy link
Copy Markdown

@amaksimo amaksimo commented Apr 14, 2026

Summary

Amazon Aurora DSQL uses CREATE INDEX ASYNC to create indexes asynchronously. This adds parsing support for the ASYNC keyword in CREATE INDEX statements, following the same pattern as the existing CONCURRENTLY keyword.

Syntax: CREATE [UNIQUE] INDEX [ASYNC] [IF NOT EXISTS] <name> ON <table>(<columns>)

Changes

  • Add ASYNC to the keyword list (keywords.rs)
  • Add pub r#async: bool field to CreateIndex struct (ast/ddl.rs)
  • Parse ASYNC keyword after CONCURRENTLY in parse_create_index (parser/mod.rs)
  • Round-trip support via Display impl
  • Update Spanned impl (ast/spans.rs)
  • Tests for CREATE INDEX ASYNC and CREATE UNIQUE INDEX ASYNC (sqlparser_postgres.rs)
  • Update all existing CreateIndex test patterns with the new field

Thanks for revewing!

Amazon Aurora DSQL uses `CREATE INDEX ASYNC` to create indexes
asynchronously. This adds parsing support for the ASYNC keyword
in CREATE INDEX statements.

Changes:
- Add ASYNC keyword to the keyword list
- Add `async` field to CreateIndex struct
- Parse ASYNC keyword after CONCURRENTLY in parse_create_index
- Round-trip support via Display impl
- Tests for CREATE INDEX ASYNC and CREATE UNIQUE INDEX ASYNC
Comment on lines +3232 to +3264
let sql = "CREATE INDEX ASYNC my_index ON my_table(col1)";
match pg().verified_stmt(sql) {
Statement::CreateIndex(CreateIndex {
name: Some(ObjectName(name)),
table_name: ObjectName(table_name),
using,
columns,
unique,
concurrently,
r#async,
if_not_exists,
include,
nulls_distinct: None,
with,
predicate: None,
index_options,
alter_options,
}) => {
assert_eq_vec(&["my_index"], &name);
assert_eq_vec(&["my_table"], &table_name);
assert_eq!(None, using);
assert!(!unique);
assert!(!concurrently);
assert!(r#async);
assert!(!if_not_exists);
assert_eq_vec(&["col1"], &columns);
assert!(include.is_empty());
assert!(with.is_empty());
assert!(index_options.is_empty());
assert!(alter_options.is_empty());
}
_ => unreachable!(),
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let sql = "CREATE INDEX ASYNC my_index ON my_table(col1)";
match pg().verified_stmt(sql) {
Statement::CreateIndex(CreateIndex {
name: Some(ObjectName(name)),
table_name: ObjectName(table_name),
using,
columns,
unique,
concurrently,
r#async,
if_not_exists,
include,
nulls_distinct: None,
with,
predicate: None,
index_options,
alter_options,
}) => {
assert_eq_vec(&["my_index"], &name);
assert_eq_vec(&["my_table"], &table_name);
assert_eq!(None, using);
assert!(!unique);
assert!(!concurrently);
assert!(r#async);
assert!(!if_not_exists);
assert_eq_vec(&["col1"], &columns);
assert!(include.is_empty());
assert!(with.is_empty());
assert!(index_options.is_empty());
assert!(alter_options.is_empty());
}
_ => unreachable!(),
}
pg().verified_stmt("CREATE INDEX ASYNC my_index ON my_table(col1)");

same for the unique one. Since the flag is already asserted in other tests, a simple round trip test scenario should suffice.

Also can we move this test to common.rs - since its not guarded specifically to postgres

Comment thread src/ast/ddl.rs
/// whether the index is created concurrently
pub concurrently: bool,
/// whether the index is created asynchronously
pub r#async: bool,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a link to the postgres docs describing the syntax?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants