Introducing the query condition cache
ClickHouse 25.3 adds a query condition cache that records, per table, data part and predicate hash, a bit per granule indicating whether any row matched the WHERE condition, so repeated filters can skip non-matching granules. On 100 million Bluesky JSON events, a selective LIKE filter that the primary index can't prune dropped from 0.53 s scanning ~99M rows to 0.037 s scanning ~2M rows on a cache hit. Because the cache is keyed on the predicate rather than the full query, different queries sharing the same filter (e.g. grouping by language or hour) also benefit. At one bit per granule, the default 100 MB cache covers ~839 million granule entries; it is off by default while edge cases like FINAL on ReplacingMergeTree are hardened.
Related posts
- Introducing the ClickHouse Query Cache
ClickHouse mediumAdept
ClickHouse v23.1 adds an experimental query cache that stores results of expensive SELECT queries for a configurable TTL (60 s by default), cutting a 9-second aggregation over 3.1 billion GitHub events to 0.04 s on repeat runs. A walkthrough shows a common pitfall: results larger than the 1 MiB default max_entry_size are silently skipped, which trace logs and system.query_cache reveal. Settings control read/write-only use, minimum query duration or run counts before caching, caching of non-deterministic functions, and sharing entries between users. The cache is deliberately transactionally inconsistent: inserts and merges don't invalidate entries, which avoids MySQL-style scalability problems. Entries are keyed by the query AST rather than its text.
- A simple guide to ClickHouse query optimization: part 1
ClickHouse mediumAdept
Slow ClickHouse queries can be diagnosed with system.query_log (duration, rows read, memory, CPU, cache metrics) and the EXPLAIN statement, illustrated on the NYC Taxi dataset in the ClickHouse Playground. A table created with an inferred schema (all Nullable columns, empty ORDER BY) forces every example query into a full scan of 329 million rows taking over a second and roughly 400–550 MiB of memory. Turning off the filesystem cache makes timings reproducible. The first part of the series then moves to basic optimizations and choosing primary keys so ClickHouse can skip data instead of scanning it.
- ClickHouse Newsletter May 2022: Explain Statement – Query Optimization
ClickHouse mediumAdept
ClickHouse's May 2022 newsletter centers on using EXPLAIN for query optimization. EXPLAIN SYNTAX reveals rewrites such as wildcard expansion and predicate pushdown into subqueries. EXPLAIN PLAN with indexes=1 shows granules read: on a 1-billion-row MergeTree table, sorting by the filtered column lets the primary key prune reads to 1 of 122,071 granules, cutting query time from 0.688s to 0.007s. The newsletter also covers the 22.4 release, which adds experimental transactions, Keeper load balancing, a RocksDB metadata cache that cut startup from 75 minutes to 20 seconds at 700k parts, and WITH FILL INTERPOLATE gap filling, plus upcoming events and revamped docs.
- ClickHouse Release 25.2
ClickHouse mediumAdept
ClickHouse 25.2 ships 12 features, 15 performance optimizations and 72 bug fixes. The parallel hash join build phase no longer locks every hash table to check size limits when max_rows_in_join and max_bytes_in_join are unset. That removes thread contention and halves a synthetic 1-billion-row join from 12.3s to 6.3s on 32 cores. Parquet output now writes Bloom filters by default, costing about 10% in file size and speeding point lookups by 30-40%. The optimizer also infers transitive conditions, such as a < 5 from a < b < 5, so primary-key pruning can apply. The release adds a read-only Backup database engine, experimental Delta Lake support via the Delta Rust kernel, and compact JSON WithProgress streaming formats over HTTP.
- ClickHouse Release 25.3
ClickHouse mediumAdept
ClickHouse 25.3 adds query support for AWS Glue and Unity lakehouse catalogs and declares the columnar JSON type, along with the Variant and Dynamic types it is built on, production-ready. It also introduces a query condition cache that reuses scan results across queries with identical selective WHERE predicates. Reads of external data such as S3 are now distributed across a cluster automatically when parallel replicas are enabled. Under the hood, the initiator node dispatches files dynamically to workers, and a 10-node example ran 4x faster. New functions include arraySymmetricDifference and estimateCompressionRatio, which compares codecs like LZ4, ZSTD and Gorilla on a column and shows how column type and sort order change the compression ratio.