Commit b3c13aa2 authored by Steve Abrams's avatar Steve Abrams Committed by Alper Akgun

Add section about temp indexes to DB docs

parent 09dbf450
...@@ -195,3 +195,34 @@ Without an explicit name argument, Rails can return a false positive ...@@ -195,3 +195,34 @@ Without an explicit name argument, Rails can return a false positive
for `index_exists?`, causing a required index to not be created for `index_exists?`, causing a required index to not be created
properly. By always requiring a name for certain types of indexes, the properly. By always requiring a name for certain types of indexes, the
chance of error is greatly reduced. chance of error is greatly reduced.
## Temporary indexes
There may be times when an index is only needed temporarily.
For example, in a migration, a column of a table might be conditionally
updated. To query which columns need to be updated within the
[query performance guidelines](query_performance.md), an index is needed that would otherwise
not be used.
In these cases, a temporary index should be considered. To specify a
temporary index:
1. Prefix the index name with `tmp_` and follow the [naming conventions](database/constraint_naming_convention.md) and [requirements for naming indexes](#requirements-for-naming-indexes) for the rest of the name.
1. Create a follow-up issue to remove the index in the next (or future) milestone.
1. Add a comment in the migration mentioning the removal issue.
A temporary migration would look like:
```ruby
INDEX_NAME = 'tmp_index_projects_on_owner_where_emails_disabled'
def up
# Temporary index to be removed in 13.9 https://gitlab.com/gitlab-org/gitlab/-/issues/1234
add_concurrent_index :projects, :creator_id, where: 'emails_disabled = false', name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :projects, INDEX_NAME
end
```
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment