Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'IF NOT EXISTS' for indexes #4727

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/sql/statements/create_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ Create index `s_idx` that allows for duplicate values on column `revenue` of tab
CREATE INDEX s_idx ON films (revenue);
```

Create index if it does not yet exist:

```sql
CREATE INDEX IF NOT EXISTS s_idx ON films (revenue);
```

> The `CREATE INDEX IF NOT EXISTS` statement does not have an “early exit” at the moment, instead, it will attempt to create the index and only check its existence before committing it to storage. Therefore, it may run for a longer time compared to other `IF NOT EXISTS` statements, which terminate early.

Create compound index `gy_idx` on `genre` and `year` columns:

```sql
Expand Down
1 change: 1 addition & 0 deletions js/statements/indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function GenerateCreateIndex(options = {}) {
Keyword("CREATE"),
Optional(Keyword("UNIQUE"), "skip"),
Keyword("INDEX"),
GenerateIfNotExists(),
Expression("name"),
Keyword("ON"),
Expression("table"),
Expand Down