Build Index
Builds an index on existing data in a table. Currently, inverted indexes and vector indexes are supported. Bloom filters are not supported.
Syntax
Parameter Description
| Parameter | Required | Description |
|---|---|---|
index_name | Yes | The name of the index to build. The index must have been defined previously via CREATE INVERTED INDEX or during table creation. |
schema | No | The schema name where the table resides. If not specified, the current schema is used. |
table_name | Yes | The name of the target table. |
WHERE clause | No | Specifies partition conditions. The index is built only on matching partitions. One or more partition columns can be specified. |
Description
CREATE INVERTED INDEX only takes effect for data written after the index is created; existing data is not automatically indexed. Executing BUILD INDEX retroactively builds the index on existing data.
BUILD INDEX is an asynchronous task. It returns immediately after submission, and the actual build process runs in the background, consuming compute resources. You can monitor the build progress via SHOW JOBS or the Job Profile.
Examples
- Build an inverted index on all existing data in the
doc_test.employeestable:
First, confirm that the index exists:
Then build the index on the existing data (switch to the corresponding schema first):
- Build an index on a specified partition of a partitioned table:
- Build an index with multiple partition conditions:
Notes
- After submission,
BUILD INDEXruns asynchronously. UseSHOW JOBSto check the task status. - Building an index on a table with a large data volume consumes significant compute resources. It is recommended to execute during off-peak hours.
- For partitioned tables, it is recommended to build indexes in batches by partition to avoid oversized single tasks.
- Index names must be unique within a schema. The
index_nameused withBUILD INDEXdoes not require a schema prefix, but ensure that the current schema matches the table's schema, or switch schemas usingUSE SCHEMA. - Related commands: Create Inverted Index, Show Index, Drop Index
