Index Cleanup
-
Indexes are essential for accelerating data retrieval and query performance.
-
However, over time, an accumulation of indexes may lead to redundant, unused, or overlapping indexes
that can consume resources and slow down the system since every time data is inserted, updated, or deleted, the corresponding indexes must be updated. -
To address this, RavenDB offers a set of index cleanup options that can help you maintain a lean and efficient indexing setup, ensuring that only valuable indexes are retained. Reducing the number of indexes the database needs to update each time data is modified can improve indexing performance and reduce resource usage.
Note that when merging or removing any indexes via Index Cleanup,
you will need to update the index references in your application's client code. -
In this page:
Merge indexes
The merge indexes option allows you to combine multiple indexes that serve similar purposes into a single, unified index. Note that the server only suggests merging indexes that index data from the same collection.
Once a new merged index definition is created, the original indexes can be removed.
For example, consider the following 2 indexes.
Both indexes index data from the Employees collection and share the common index-field Title
.
Index 1: EmployeesByFirstNameAndTitle
Index 2: EmployeesByLastNameAndTitle
Open the Index Cleanup view in the Studio (Indexes > Index Cleanup view).
The server will suggest merging those two indexes:
Merge indexes
- Go to Indexes > Index Cleanup.
- Open the Merge indexes tab.
- The suggested indexes that can be merged.
- Click to review the suggested new index.
Review suggested merge
- Provide a name for the new index.
- This is the suggested map function that combines the index-fields from the original two indexes.
In this example the new index contains all 3 fields:FirstName
,LastName
, andTitle
. -
Before saving this index:
- Review the suggested index-fields.
- In addition, you can configure any index-field or customize the indexing configuration for this new index as needed.
After saving the new index, the next dialog will ask you whether you wish to delete the original two indexes.
Delete original indexes
Remove sub-indexes
If an index is completely covered by another index (i.e., all its fields are present in a larger index),
maintaining it adds unnecessary overhead without providing additional value.
You can remove the sub-index without losing any query optimization benefits.
For example, consider the following 2 indexes.
All index-fields of the ProductsByNameAndSupplier
index are contained within the ProductsByNameSupplierAndCategory
index.
Index 1: ProductsByNameAndSupplier
Index 2: ProductsByNameSupplierAndCategory
The server will suggest removing the sub-index ProductsByNameAndSupplier
:
Remove sub-index
- Go to Indexes > Index Cleanup and open the Remove sub-indexes tab.
- The sub-indexes that can be safely deleted are listed here.
- Click to delete the selected sub-indexes.
Remove unused indexes
Indexes that haven’t been queried for a period of time still consume resources,
such as storage space and processing power needed to keep indexed data up-to-date.
The Remove unused indexes tab lists indexes that have Not been queried for over a week.
Review the list and consider deleting any unnecessary indexes.
Remove unused indexes
- Go to Indexes > Index Cleanup and open the Remove unused indexes tab.
- The indexes that have not been queried for over a week are listed here.
Select the indexes you wish to delete. - Click to delete the selected indexes.
Indexes that will not be merged
-
Static-indexes that belong to the following categories will Not be considered by the server for merging or for removing a sub-index. These indexes will be listed under the Unmergeable indexes tab, with a specific reason provided for each index.
- Map-reduce indexes
- Multi map indexes
- Fanout indexes
- Indexes that use a
where
clause in their index definition - Indexes that load a related document in their index definition
- Indexes that use
let
in their LINQ index definition - only when deployed via the PutIndexesOperation syntax - Indexes for which the server did not find any other index to merge with
-
JavaScript indexes are also excluded from merging but are Not listed in this view.
-
Auto-indexes are automatically merged by the server and will Not be listed in this view.
Unmergeable indexes
- Go to Indexes > Index Cleanup and open the Unmergeable indexes tab.
- The indexes that are not mergeable are listed here.
Merge suggestions errors
The Merge suggestions errors tab lists errors that were encountered while trying to create index merge suggestions. This tab will only appear if the server has encountered any such errors.
Merge suggestions errors
- The Merge suggestions errors tab will appear only if the server has encountered any such errors.
- Indexes that caused the errors are listed here.
- Click Show details to view the full error information.