Introducing the ClickHouse Query Cache
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.
Related posts
- Introducing the query condition cache
ClickHouse mediumAdept
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.
- 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 Release 23.1
ClickHouse mediumAdept
ClickHouse 23.1 adds experimental inverted full-text indices as a data-skipping index, parameterized views, and a TTL-based query results cache, alongside 17 features, 17 performance optimisations and 78 bug fixes. On Hacker News data, the inverted index cuts a token-match query from 0.56s scanning 34M rows to 0.29s scanning 6M rows. It stores no term positions or relevancy statistics and supports only whitespace or n-gram tokenization, so it accelerates token matching but does not replace a search engine. The query cache is deliberately not transactionally consistent: entries expire only by TTL, trading accuracy for performance in OLAP workloads like dashboards.
- Trade secrets: How Coinhall uses ClickHouse to power its blockchain data platform
ClickHouse easyNovice
Coinhall, an omnichain trading terminal aggregating swap data from 23 blockchains, moved from BigQuery (about 2-second queries, thousands of dollars per month) to QuestDB and then to self-hosted ClickHouse. In Coinhall's comparison against Rockset, SingleStore and Snowflake, ClickHouse ran candlestick queries in 20 ms, latest-price queries in 8 ms and ASOF JOINs in 50 ms, on a 4 vCPU / 16 GB server costing about $50 a month. After migrating, the team tuned queries around sparse primary indexes and replaced full-table LIMIT BY scans with aggregating tables fed by materialized views. They also avoided or simplified sort-merge joins.
- How Rokt Achieved Real-time Reporting with ClickHouse
ClickHouse easyNovice
Rokt replaced an Elasticsearch-backed reporting layer with ClickHouse. Elasticsearch lacked flexible group-by and filtering, had no S3 loading or joins, required JSON queries, and forced full re-ingestion whenever a label changed. After ruling out Pinot, Druid, Snowflake, StarRocks and Citus, the team benchmarked ClickHouse against Redshift: ClickHouse was about 3x cheaper, handled up to 200 queries per second with a maximum query time of six seconds, and stored 500 GB of gzipped Parquet in roughly the same space, about one sixth of the Elasticsearch footprint. The current self-managed setup runs ClickHouse in an autoscaling group with ZooKeeper behind network load balancers, and Rokt plans to move to ClickHouse Cloud to offload replication, sharding and backups.