CREATE INDEX adds data-skipping indexes to ClickHouse tables for faster query filtering.
CREATE INDEX defines a data-skipping index that lets ClickHouse quickly exclude data parts not matching filter conditions. It reduces disk reads and speeds up large table scans.
Add an index when queries repeatedly filter on the same columns and the column’s cardinality allows effective skipping.Typical targets are date ranges, numeric amounts, and low-to-medium cardinality dimensions.
Use ALTER TABLE … ADD INDEX with the column expression and an index type such as minmax, set, or bloom_filter.
ALTER TABLE table ADD INDEX idx_name expression TYPE type(params) GRANULARITY N;
Wrap multiple columns in a tuple expression.Composite indexes help when filters combine the same columns in WHERE clauses.
DROP INDEX removes it, and REPLACE INDEX recreates it in one step. Both require a mutation and may take time on large tables.
Pick the smallest useful GRANULARITY (usually 1–4) to balance speed and index size. Test with realistic queries and system.parts
statistics. Avoid over-indexing—each index increases storage and insertion cost.
.
The command runs as a background mutation. Reads continue, but inserts slow slightly until the index is built.
You can only add indexes to ordinary or MergeTree-engine tables. Apply indexes to the source table rather than the view.