Index-based pruning in ClickHouse
ClickHouse offers three index-based ways to skip data: the sparse primary index (one entry per 8,192-row granule), lightweight projections that store only a sort key plus a _part_offset pointer into the base table, and skip indexes such as minmax that keep per-granule min/max values. On a 243-million-row UK property sales table, a filter on the leading primary-key column read 1.69 million rows in 15 ms. Filtering only on the second key column fell back to generic exclusion search, scanned 138 million rows and ran 50x slower. Lightweight projections handle filters on non-key columns without duplicating full rows, while minmax indexes cost even less storage but only prune well when the column correlates with the primary key.
Related posts
- ClickHouse projections now behave like true secondary indexes
ClickHouse mediumAdept
ClickHouse lightweight projections, which store only a sorting key plus a _part_offset pointer into the base table, now act as true secondary indexes with granule-level pruning instead of only pruning whole parts. Several such projections can combine with each other and with the base table's primary index to narrow the granules a query reads. On the UK price paid dataset, a query filtering on date and town dropped from a 30.7M-row full scan in 0.077 s to about 16k rows in 0.010 s, and EXPLAIN shows both projection indexes pruning granules in turn. Two new settings gate when projection indexes are used, and 26.1 adds a compact `PROJECTION ... INDEX col TYPE basic` syntax.
- How ClickHouse makes Top-N queries faster with granule-level data skipping
ClickHouse mediumAdept
ClickHouse can now use minmax data-skipping indexes to prune whole granules for ORDER BY … LIMIT N queries before reading any rows. Without predicates, it preselects only the granules with the smallest min (or largest max) values. With predicates, it keeps a dynamic N-th-value threshold during streaming execution and skips granules whose min/max cannot improve the result. On the 100M-row hits dataset, enabling use_skip_indexes_for_top_k and use_top_k_dynamic_filtering made Top-N queries 5–10× faster and cut data read by 10–100×, and a 50B-row production table answered in under 0.2 s. The pruning composes with streaming Top-N, read-in-order and lazy reading, and it pays off most on large tables, cold caches and object storage.
- Super charging your ClickHouse queries
ClickHouse mediumAdept
ClickHouse query speed comes mainly from reading less data: a sparse primary index stores one entry per 8192-row granule and lets binary search skip blocks that can't match the WHERE clause. On the 27.6M-row UK property dataset, re-sorting a copy of the table by (town, price) cuts a full scan to 81.92 thousand rows, and optimize_read_in_order removes the in-memory sort and stops early under LIMIT. Projections do the same job automatically, as hidden tables kept in sync with the main table that can use a different sort order or pre-computed aggregates (backed by AggregatingMergeTree). ClickHouse picks the cheapest projection at query time. Raising query-engine parallelism is the third tuning knob.
- Top 10 best practices tips for ClickHouse
ClickHouse mediumAdept
Ten practices for getting performance and storage efficiency out of ClickHouse, each measured on a 150M-row Amazon reviews dataset. Aligning ORDER BY with query filters (low-cardinality columns first) made one query 3x faster and cut scanned data 347x. Right-sized types, no Nullable and LowCardinality(String) doubled query speed and shrank storage. Partitioning is best avoided except for TTL expiry or FINAL on merge engines; monthly partitions slowed one aggregation 46x. The post also covers lightweight versus heavyweight skipping indexes, JSON type hints (38% less storage, 26% faster), and preferring Parquet/ORC for bulk ingestion.
- ClickHouse Release 25.12
ClickHouse hardMaster
ClickHouse 25.12 ships 26 features, 31 performance optimizations and 129 bug fixes, led by three query-engine speedups. Top-N queries (ORDER BY … LIMIT N) now compare the running threshold against granule-level min/max skip-index metadata to skip granules before reading, cutting data read by one to two orders of magnitude and speeding queries 5–10×. Lazy materialization moved from row-by-row column fetches to a batched join-style step (JoinLazyColumnsStep), making a LIMIT 100,000 query about 75× faster (38.7s to 0.51s), and its default limit was raised from 10 to 10,000. An experimental DPsize dynamic-programming join reordering algorithm for INNER JOINs explores more join orders than the greedy approach and produces a better plan on a TPC-H eight-table query.