Free audit

View Audit Scope

Execution — query rewrites, schema tuning, config remediation

ClickHouse Performance Tuning

In short: ClickHouse performance tuning involves MergeTree compaction tuning, projection design, and query optimization (PREWHERE placement, JOIN reordering), plus shard-key audit for skew, replication-lag remediation via ZooKeeper/Keeper, and balancing memory limits against concurrent_query ceilings — delivered as written recommendations with before/after benchmarks.

MergeTree compaction tuning, projection design, query rewrites (PREWHERE, JOIN order), shard-key audit, replication lag remediation — for production ClickHouse workloads with before/after benchmarks. See ClickHouse consulting for the architecture-decision phase or migration runbooks.

Executive Direct Answer · ClickHouse Performance Tuning Heuristic

JusDB delivers enterprise ClickHouse performance tuning to eradicate compaction backlogs, optimize memory ergonomics, and accelerate complex analytical queries. Our DBREs calibrate background pool threads, optimize PREWHERE execution pushdowns, design secondary projections, and resolve distributed query skew across production clusters.

Query Latency: Measured Before & After·Response Targets: Per Agreement·Merges: Parts Backlog Monitored·Filtering: PREWHERE Pushdown Optimized·ISO 27001 & SOC 2 Type II: aligned, certification in progress

Sound familiar?

  • ▸ Compaction backlog — system.parts shows tens of thousands of parts per partition and ingestion is throttling at max_parts_in_total.
  • ▸ p99 query latency cliff — analyst queries that were sub-second three months ago now run 10-30 seconds, and the team doesn't know why.
  • ▸ Replication lag — ZooKeeper or Keeper is the suspect but the team needs a defensible tuning plan before scaling.

JusDB ClickHouse performance specialists run query-log audits and ship before/after benchmarks. Request a ClickHouse perf tuning call →

What our ClickHouse perf tuning covers

Each engagement ships query rewrites, schema tuning, and config remediation with documented before/after benchmarks.

MergeTree Compaction

background_pool_size tuning, merge frequency, max_parts_in_total balance, OPTIMIZE FINAL strategy for catching up on backlog.

Projection Design

Same-table query-rewrite acceleration mapped from system.query_log digest analysis — replace expensive ad-hoc patterns with projections.

Query Optimization

PREWHERE placement, JOIN reordering, materialized-view-aware filtering, SETTINGS hints for parallelism and memory.

Replication Lag

ClickHouse Keeper quorum/session tuning, system.replication_queue depth analysis, replica fetch/merge throughput (background_fetches_pool_size, max_replicated_fetches_network_bandwidth).

Memory & Concurrency

max_memory_usage per query, max_concurrent_queries, max_server_memory_usage — balanced against working-set + ingestion.

Shard-Key Audit

Skew detection via system.parts distribution, shard rebalance strategy, Distributed-table layer tuning.

How JusDB ClickHouse Performance Tuning compares to alternative models.

Standard cloud defaults and generalist DBAs fail to configure SIMD vectorization, secondary projections, PREWHERE pushdowns, and async_insert buffer architectures. Here is how our ClickHouse DBREs compare:

Evaluation Vector
JusDB DBRE
In-House DBALegacy AgencyDeveloper Generalist
MergeTree Parts & Compaction (background_pool_size)Tunes background_pool_size, background_merges_mutations_concurrency, and max_bytes_to_merge_at_max_space_in_pool to balance merge throughput against NVMe IOPS, eliminating 'Too many parts' errors.Runs frequent manual OPTIMIZE TABLE ... FINAL commands during daytime traffic, causing severe I/O spikes and blocking read queries.Leaves background pool at defaults; when parts backlog builds, restarts the database service, worsening unmerged parts count.Increases max_parts_in_total to arbitrarily high thresholds, ignoring the root cause until the filesystem runs out of inodes.
PREWHERE Pushdown & Columnar VectorizationRestructures complex analytical queries to leverage automatic PREWHERE condition pushdown and SIMD-vectorized filter execution, reducing the columnar bytes each query reads.Relies on standard WHERE clauses without verifying filter selectivity or columnar scan reduction via EXPLAIN PIPELINE.Attempts to speed up slow scans by creating traditional B-Tree indexes, unaware of ClickHouse columnar sparse indexing mechanics.Fetches full row payloads with SELECT * into application memory, destroying ClickHouse columnar read vectorization benefits.
Secondary Projection vs Skipping Index DesignEngineers secondary projections with alternative ORDER BY keys and calibrated data skipping indices (minmax, set, bloom_filter) with optimal granularity to bypass petabyte scans.Adds bloom_filter skipping indices on low-cardinality columns without tuning granularity, adding index calculation overhead with zero row skipping.Avoids projections due to lack of operational understanding, defaulting to heavy multi-table materialized views for simple sort-order variants.Creates dozens of experimental skipping indexes blindly, increasing table mutation overhead and part serialization times.
Memory Limits (max_bytes_before_external_group_by)Configures max_bytes_before_external_group_by and max_bytes_before_external_sort to spill massive aggregations to temp NVMe storage, preventing Code 241 OOM query terminations.Simply increases max_memory_usage per user until concurrent heavy queries exhaust host RAM and trigger Linux kernel OOM kills.Fails to configure spill-to-disk thresholds; tells analysts to restrict query date ranges whenever queries crash.Leaves memory settings unmanaged; single runaway analytical queries crash the primary ClickHouse server daemon.
High-Concurrency async_insert Buffer SizingEnables async_insert=1, tunes async_insert_busy_timeout_ms (200ms) and async_insert_max_data_size (100MB) to consolidate micro-batches into optimal part sizes at 1M+ rows/sec.Requires application teams to maintain complex external micro-batching daemons in front of ClickHouse, increasing architectural fragility.Inserts individual rows synchronously over HTTP, generating thousands of tiny parts per second and choking disk merge queues.Disables async insert settings due to misunderstanding durability trade-offs, leading to persistent insertion timeouts under load.
Distributed Query Plan & JOIN ColocationOptimizes distributed query plans by collocating shard keys for distributed JOINs (GLOBAL vs LOCAL IN), eliminating high-latency cross-node network shuffle amplification.Uses GLOBAL JOIN on massive tables across all shards, saturating cluster network interfaces and causing query execution timeouts.Extracts data from ClickHouse into external Python/Pandas processes to perform joins due to fear of distributed query memory limits.Executes un-sharded subqueries across distributed tables, multiplying query work by the shard count across the entire cluster.

Critical ClickHouse Latency Outage Modes We Eliminate

Columnar analytical engines achieve sub-second P99 latencies only when compaction backlogs, unbounded distributed joins, and unindexed table scans are proactively prevented. Our DBREs remediate these critical failure modes:

P1 Critical

Too Many Parts Error (Code 252) Halting Production Ingestion

Micro-batch insertion rates exceed background merge compaction capacity, causing active parts per partition to surpass max_parts_in_total (300). ClickHouse throws Code 252 errors and abruptly halts real-time write ingestion.

JusDB Engineering Mitigation:

JusDB enables async_insert=1 with calibrated busy timeouts, scales background_pool_size and background_merges_mutations_concurrency, and balances partition key granularity to maintain healthy part counts.

P1 Critical

Memory Limit Exceeded (Code 241) on Unbounded Global JOIN

Complex multi-tenant analytics executing unindexed GLOBAL JOIN queries across large distributed tables create massive in-memory hash tables that breach max_bytes_before_external_group_by or max_memory_usage, abruptly aborting critical queries.

JusDB Engineering Mitigation:

JusDB redesigns queries using shard-collocated LOCAL JOINs, configures graceful external disk spilling (max_bytes_before_external_join), and creates projection indices for high-frequency join keys.

P2 High

Suboptimal ORDER BY Tuple Missing Granular Index Pruning

Fact tables with ORDER BY primary keys that do not align with dominant query filter hierarchies force full partition scans, reading hundreds of gigabytes of columnar data instead of pruning granule marks.

JusDB Engineering Mitigation:

JusDB audits slow query digests in system.query_log, realigns primary sorting key tuples by filter selectivity, and introduces secondary projections for orthogonal filter workloads.

Telemetry Runbooks · Non-Blocking ClickHouse Tuning Diagnostics

Our ClickHouse DBREs execute non-blocking profiling telemetry to isolate slow query bottlenecks and monitor active merge pipelines without interrupting analytical query workloads:

ClickHouse: Top Slow Queries & Memory Spills Forensics
SQL · Query Telemetry

Queries system.query_log to identify highest latency queries, peak memory footprints, and heavy columnar data scans from today's workload.

SELECT 
  query_id, 
  user, 
  query_duration_ms, 
  memory_usage, 
  read_rows, 
  formatReadableSize(read_bytes) 
FROM system.query_log 
WHERE type = 'QueryFinish' 
  AND event_date = today() 
ORDER BY query_duration_ms DESC 
LIMIT 10;
ClickHouse: Active Merge Pipeline & Disk Write Telemetry
SQL · Merge Telemetry

Inspects active background merge tasks, progress percentages, part counts being merged, and write volume across all tables.

SELECT 
  database, 
  table, 
  elapsed, 
  progress, 
  num_parts, 
  formatReadableSize(total_size_bytes_compressed) 
FROM system.merges;

ClickHouse perf tuning — common questions

MergeTree compaction tuning (parts merging strategy, background_pool_size), projection design (when projections beat materialized views for read acceleration), query optimization (PREWHERE placement, JOIN reordering, SETTINGS hints), shard-key audit for skew correction, replication lag remediation (ZooKeeper / Keeper tuning), memory limits + max_concurrent_queries balance. Deliverables are written tuning recommendations with before/after benchmarks.

system.query_log analysis to identify dominant slow patterns by digest, then EXPLAIN PIPELINE + EXPLAIN ESTIMATE on representative queries. Common findings: missing PREWHERE on selective filters (5-50x speedups), suboptimal JOIN order on multi-table queries, sort key not aligned with query filter columns, materialized view that should be a projection, or compaction backlog on ReplacingMergeTree. We've never seen a slow-ClickHouse audit without at least 3 of these issues.

First diagnose: system.parts tells you parts-per-partition; system.merges shows active merges. Backlog usually means background_pool_size is too small for ingestion rate, or max_parts_in_total has been hit forcing inserts to throttle. Fix: increase background_pool_size carefully (more merges = more I/O), tune merge_max_block_size, consider FINAL modifier or OPTIMIZE FINAL during low-traffic windows. For ReplacingMergeTree-heavy workloads, sometimes CollapsingMergeTree is the better choice.

Projections: same-table read acceleration, automatic query rewrite by optimizer, share base-table partition lifecycle. Materialized views: fan-out to differently-shaped target tables, can target different MergeTree variants, don't slow down base SELECTs. Use projections for ad-hoc query acceleration on existing tables. Use MVs for downsampling, aggregation roll-ups feeding dashboards, or cross-shard fanout patterns. We audit query patterns to map each slow query to the right tool.

ClickHouse Cloud auto-scales compute per workload, billing per-second — easier to tune. Self-managed needs explicit sizing: parts-per-second ingestion rate, working-set RAM requirements, CPU cores per shard, replica count. We model both against your workload before recommending sizing strategy. For the broader engine-decision phase, see our ClickHouse consulting service.

Yes — query rewriting is often the highest-leverage intervention. We rewrite queries with proper PREWHERE, JOIN order, materialized-view-aware filtering, and SETTINGS hints. Schema changes (sort keys, partition keys, index types) require coordination with engineering. Configuration changes (memory limits, pool sizes, compaction settings) we apply to staging first, validate, then production.

Ready to fix ClickHouse performance?

Book a 30-minute scoping call. We'll review query-log digests, surface optimization opportunities, and propose the right engagement shape.

Related ClickHouse Services

Explore more ways our ClickHouse experts can help with your database infrastructure.