Data Skipping Index Examples
This page consolidates ClickHouse data skipping index examples, showing how to declare each type, when to use them, and how to verify they're applied. All features work with MergeTree-family tables.
Index syntax: INDEX name expr TYPE type(...) [GRANULARITY N]
ClickHouse supports five skip index types:
- minmax - Tracks minimum and maximum values in each granule
- set(N) - Stores up to N distinct values per granule
- bloom_filter([false_positive_rate]) - Probabilistic filter for existence checks
- ngrambf_v1 - N-gram bloom filter for substring searches
- tokenbf_v1 - Token-based bloom filter for full-text searches
Each section provides examples with sample data and demonstrates how to verify index usage in query execution.
MinMax index
Best for range predicates on loosely sorted data or columns correlated with ORDER BY.
See a worked example with EXPLAIN and pruning.
Set index
Use when local (per-block) cardinality is low; not helpful if each block has many distinct values.
Creation/materialization workflow and before/after effect are shown in the basic operation guide.
Generic Bloom filter (scalar)
Good for "needle in a haystack" equality/IN membership. Optional parameter is the false-positive rate (default 0.025).
N-gram Bloom filter (ngrambf_v1) for substring search
Splits strings into n-grams; works well for LIKE '%...%'. Supports String/FixedString/Map (via mapKeys/mapValues). Tunable size, hash count, seed. See documentation for N-gram bloom filter.
This guide shows practical examples and when to use token vs ngram.
Parameter optimization helpers:
The four ngrambf_v1 parameters (n-gram size, bitmap size, hash functions, seed) significantly impact performance and memory usage. Use these functions to calculate optimal bitmap size and hash function count based on your expected n-gram volume and desired false positive rate:
See parameter docs for complete tuning guidance.
Token Bloom filter (tokenbf_v1) for word-based search
Indexes tokens separated by non-alphanumeric characters; use with hasToken, LIKE word patterns, equals/IN. Supports String/FixedString/Map. See: Token bloom filter and Bloom filter types.
See observability examples and guidance on token vs ngram here.
Add indexes during CREATE TABLE (multiple examples)
Also supports composite expressions and Map/Tuple/Nested.
Materializing on existing data and verifying
Add an index to existing data parts using MATERIALIZE, and inspect pruning with EXPLAIN or trace logs.
A worked minmax example demonstrates EXPLAIN output structure and pruning counts.
When use and when to avoid
Use skip indexes when:
- Filter values are sparse within data blocks
- Strong correlation exists with ORDER BY columns or data ingestion patterns group similar values together
- Performing text searches on large log datasets (ngrambf_v1/tokenbf_v1 types)
Avoid skip indexes when:
- Most blocks likely contain at least one matching value (blocks will be read regardless)
- Filtering on high-cardinality columns with no correlation to data ordering
Important considerations: If a value appears even once in a data block, ClickHouse must read the entire block. Test indexes with realistic datasets and adjust granularity and type-specific parameters based on actual performance measurements.
Temporarily ignore or force indexes
Disable specific indexes by name for individual queries during testing and troubleshooting. Settings also exist to force index usage when needed. See ignore_data_skipping_indices.
Notes and caveats
- Only supported on MergeTree-family tables; pruning happens at the granule/block level.
- Bloom-filter-based indexes are probabilistic (false positives cause extra reads but won't skip valid data).
- Bloom filters and other skip indexes should be validated with EXPLAIN and tracing; adjust granularity to balance pruning vs. index size.