ClickHouse lets you tune, flush, and monitor its mark, uncompressed, and query caches to speed up repeat reads or free memory.
Cache behavior covers how ClickHouse stores recently read data blocks (mark & uncompressed cache) and finished result sets (query cache) in RAM. Proper tuning avoids wasted memory and maximizes hit-rate for repetitive queries.
Set use_query_cache
per session or per query. A value of 1
stores results; 0
bypasses the cache.Combine with query_cache_min_query_duration_ms
to avoid caching trivial queries.
Use SYSTEM DROP [MARK|UNCOMPRESSED|QUERY] CACHE
to free specific caches instantly. Handy after large batch loads or schema changes that make cached data obsolete.
Increase sizes when dashboards reread the same columns frequently and the server still has free RAM.Decrease or disable when workloads are highly ad-hoc or RAM is scarce.
An ecommerce dashboard repeatedly totals Orders
by day. Enabling the query cache and ensuring hot columns stay in the mark cache cuts latency from seconds to milliseconds.
Start with defaults, monitor MarkCacheEntries
and QueryCacheHits
, then increment sizes gradually. Always drop caches after heavy INSERT
batches to prevent stale data.
See dedicated section below.
Scroll down.
.
No. Caches apply only to data read paths. Newly inserted parts become eligible for caching on the next read.
Query system.metrics for QueryCacheHits
, MarkCacheHits
, and UncompressedCacheHits
to gauge effectiveness.
No. All three caches are in-memory structures cleared on restart. Persistent local volumes are unaffected.