1. Add a skip index
ADD INDEX attaches a secondary skip index on a non-key column.
ADD INDEX idx_status status TYPE minmax GRANULARITY 4Typorithm · hard
Step 1 of 8 · intro card
Indexing & Partitioning
A data skipping index like minmax (or bloom_filter) on a non-key column lets ClickHouse skip granule blocks where the value provably cannot match.
Secondary, or data skipping, indexes summarize a non-ORDER-BY column over blocks of GRANULARITY granules, so the engine can skip blocks that cannot contain a match.
A minmax index stores the min and max of the column per block; a bloom_filter index answers set-membership for equality and IN filters.
Skip indexes are added with ALTER TABLE ... ADD INDEX and built over existing rows with MATERIALIZE INDEX; they help only when the column correlates with the sort order.
Skip index summarizes a non-key column.
minmax skips by range; bloom_filter by membership.
GRANULARITY groups granules per index block.
ALTER TABLE logs
ADD INDEX idx_status status TYPE minmax GRANULARITY 4;
ALTER TABLE logs MATERIALIZE INDEX idx_status;
SELECT count()
FROM logs
WHERE status = 500;Connect each part of the code to the concept before you type.
ADD INDEX attaches a secondary skip index on a non-key column.
ADD INDEX idx_status status TYPE minmax GRANULARITY 4minmax stores the min and max of each block so non-matching blocks are skipped.
TYPE minmaxMATERIALIZE builds the skip index over rows already in the table.
MATERIALIZE INDEX idx_statusRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.