REBUILD
statementAvailable since: v1.5.0
The REBUILD
statement is used to rebuild resources in SurrealDB. It is usually used in relation to a specified Index to optimize performance. It is useful to rebuild indexes because sometimes M-TREE and HNSW index performances can degrade due to frequent updates.
Rebuilding the index will ensure the index is fully optimized.
NoteRebuilds are concurrent or sync based on how the index is defined. For example, if you define an index with the
CONCURRENTLY
option, the rebuild will be concurrent. Please see theCONCURRENTLY
clause section for more information.
SurrealQL SyntaxREBUILD [ INDEX [ IF EXISTS ] @name ON [ TABLE ] @table ]
NoteThe
IF EXISTS
and TABLE clauses are optional.
For example, if you have a table called book
and you have an index called uniq_isbn
on the isbn
field, you can rebuild the index using the following query:
REBUILD INDEX uniq_isbn ON book;
Available since: v1.3.0
The following queries show an example of how to rebuild resources using the IF EXISTS
clause, which will only rebuild the resource if it exists.
REBUILD INDEX IF EXISTS uniq_isbn ON book;