Keeping ClickHouse fast as it grows: the decisions that matter on 26.8 LTS

What to settle in ClickHouse before the data gets big, from the sort key to the limits that stop one bad query from taking the server down.

In one of ClickHouse's own tests, an aggregation ran 46 times slower on a table split into too many partitions than on the same data left unpartitioned. The query was identical. The only difference was a partitioning choice that sounds reasonable when you make it and only starts to hurt once the parts pile up.

Most ClickHouse slowdowns work this way. The engine is fast enough to hide a poor decision while a table is small, and the cost arrives when the table grows. By then the fix is often a new table and a full reload.

This post covers fifteen of those decisions. For each one I describe what to choose, what it looks like when you get it wrong, and the setting or DDL behind it. They follow roughly the order you'll meet them: schema first, because those choices are the most expensive to reverse, then ingestion, then query speed, then what only shows up in production.

Everything here is written against ClickHouse 26.8 LTS. A few practices rely on recent features, so check them against the version you run. The performance figures are ClickHouse's own, from the sources at the end. Use them to judge where effort pays off, and expect your own numbers to differ.

Schema design

You make these three once, and they cost the most to change. A wrong sort key means a new table and a reload.

1. Build the sort key from the filters your queries use

ORDER BY sets how rows sit on disk, and that layout decides what the sparse primary index can skip. Put the low-cardinality columns most queries filter on first, then time. On a multi-tenant table that usually means the tenant or account id, then the timestamp. On a single-tenant table where every query is a time range, time goes first.

To check, compare the leading columns of the key with the WHERE clauses your workload actually sends. A key ordered to look tidy in a schema browser won't prune anything. In ClickHouse's benchmark, matching the key to the filters made the query three times faster and cut the data it read by a factor of 347.

When a second set of queries needs a different order, add a projection instead of keeping a second copy of the table (practice 11).

2. Use the smallest type that fits

Pick the smallest integer that covers the range. Use LowCardinality(String) for text columns with fewer than about ten thousand distinct values, and Enum for fixed sets. Make a column Nullable only when null means something: each nullable column carries its own null map, and it can't go in the primary key unless allow_nullable_key is set.

On ClickHouse's 150-million-row test set, tighter types took storage from 30.16 GB to 26.8 GB and roughly halved query time. The saving carries into everything else in this post, because every other optimization then runs on less data.

3. Partition for data lifecycle, not for query speed

Partitions exist so a TTL can expire a whole month in one operation, and so you can detach, drop or move a partition as a unit. They also limit how much work FINAL does on merge engines. Filtering on the partition key does skip data, but if time is already in the sort key, the primary index handles that anyway.

Keep partitions to a few dozen. Thousands of them mean thousands of small parts, slower merges and more memory on ingest. ClickHouse's over-partitioned test table ran an aggregation 46 times slower than the unpartitioned version and used 4.71 GB of ingest memory against 3.03 GB.

vertical_merge_optimize_ttl_delete is on by default and makes TTL deletes cheaper on wide tables. It doesn't change how many partitions you should have.

Getting data in

ClickHouse works best with large blocks, and most ingestion trouble comes down to writing too many small parts.

4. Batch at the source, and know what async inserts already do

Asynchronous inserts have been on by default since 26.3 LTS. The server buffers small writes and flushes them into parts with no client configuration. Code that still sets async_insert = 1 is restating the default. Code that sets async_insert = 0 opts out, and that should be a choice someone made on purpose rather than one copied from an old config.

Keep batching anyway. High-volume producers such as Kafka consumers and ETL jobs should still send large blocks. The server-side buffer is there to make the long tail of small writers safe, and where you control the writer, batching still does the job better.

The setting that needs a decision is wait_for_async_insert. At the default of 1, the client is acknowledged only after the data is flushed to disk. At 0 it's acknowledged on receipt, which is faster, but a failed flush then shows up only in system.asynchronous_insert_log. The docs recommend leaving it at 1 in production. If you set it to 0, alert on that table. A flush triggers on whichever buffer threshold is reached first, async_insert_max_data_size or async_insert_busy_timeout_max_ms.

This interacts with practice 1. max_insert_threads now defaults to auto, so INSERT SELECT runs in parallel and row order within a part can differ from what older builds produced. Set it to 1 if anything downstream relies on insertion order.

5. Load bulk data as Parquet or ORC

When ClickHouse reads files from object storage, columnar formats let it read only the columns it needs, in a layout close to how it stores them. In ClickHouse's 150-million-row load test, Parquet and ORC each finished in 79 seconds, Avro in 94 and JSON in 105.

If you own the job that writes those files, switching its output format is usually a one-line change.

6. Choose the Postgres path by the constraint you actually have

There are now three ways to move Postgres data into ClickHouse, and each suits a different situation.

ClickPipes Postgres CDC is the managed connector, generally available and built on logical replication. It's the sensible default on RDS, Aurora or Cloud SQL, and whenever you'd rather not run the pipeline yourself.

WalShadow is an open-source engine (AGPL-3.0) that reads the physical WAL stream instead of going through logical decoding. That removes the replication slot, which is where most CDC pain comes from: slots that bloat, pressure to retain WAL, and decoding load on the primary. ClickHouse reports about 200 ms from commit to visible, compared with about 10 seconds on its logical path. WalShadow needs Postgres 16 or newer, wal_level = logical on the source, and a replica identity on every replicated table. It's also new, so expect to spend time in its issue tracker, and confirm that your provider exposes the physical WAL stream before you design around it.

ClickHouse Managed Postgres is in public beta. It runs Postgres on NVMe storage with CDC into ClickHouse and the pg_clickhouse extension, which lets an application send ClickHouse queries over a Postgres connection. It suits teams that want transactions and analytics behind one connection instead of an application routing between two systems. The trade-off is running your Postgres with a vendor whose main business is the analytical side.

The right one depends on what you're short of: time to operate a pipeline, replication speed, or a single connection for both workloads.

Making queries fast

With the schema right, most of the remaining gains come from reading fewer granules and joining less data.

7. Declare statistics on join keys and turn on runtime join filters

Join planning has improved a lot over the past two years. Predicate pushdown on both sides of a join, automatic reordering that puts the smaller table on the right, and reordering across three or more tables all arrived in that time and are on by default. Two newer additions need a decision from you.

enable_join_runtime_filters_index_analysis takes the join keys from the build side and uses them to skip probe-side granules before they're read. On ClickHouse's test query it was 6.2 times faster and used 8.8 times less memory. Setting query_plan_optimize_join_order_algorithm = 'dpsub' turns on dynamic-programming join ordering, which also handles non-inner joins. Try it on multi-table queries and compare both versions with EXPLAIN ANALYZE.

Both rely on cardinality estimates, and those come from column statistics, which ClickHouse only collects when you declare them:

CREATE TABLE orders
(
    customer_id UInt32 STATISTICS(uniq, basic),
    status      LowCardinality(String),
    placed_at   DateTime
)
ENGINE = MergeTree
ORDER BY (customer_id, placed_at);

For tables up to 25 GiB, declared statistics are materialized on insert by default, so the planner works from current estimates without waiting for merges. Above that size, materialize them yourself. Declare uniq and basic on join keys. Leave out tdigest and countmin unless you need percentile or frequency estimates, because the docs warn about their ingest cost.

On serving paths with millisecond targets, three or four joins per query is still a sensible ceiling, however good the planner gets.

8. Replace lookup joins with dictionaries

For reference data that rarely changes, a dictionary sits in memory and you read it with dictGet, which skips the hash join altogether. In ClickHouse's 150-million-row enrichment test, a regular join took 2.3 seconds, a join against a dictionary-backed table took 1.36 seconds, and dictGet took 0.86 seconds.

Joins against tables of countries, plans, feature flags or account metadata are all candidates, and the rewrite usually stays inside one query.

9. Add skipping indexes only where values are clustered

A skipping index stores a summary for each block of granules, and the engine skips a block when its summary rules out the filter. That only helps if the values are clustered along the sort order. A minmax index on a column whose values are spread evenly across every granule can't skip anything, however cheap it is to maintain, and that's why so many added indexes make no measurable difference.

minmax and set(N) cost almost nothing to store, so try them first for numeric ranges and low-cardinality filters. ClickHouse's minmax index on total_votes cut a scan from 150 million rows to 29 million. Bloom filters (bloom_filter, ngrambf_v1, tokenbf_v1) and text indexes cost insert time and disk, so add them only when you have a reason.

CREATE HYPOTHETICAL INDEX, still experimental, asks the planner whether it would use an index before you build it. Run it against your slowest filters first.

10. Try the text index before running a second search system

Text indexes became generally available early in 2026 and now do much more than match tokens. They speed up LIKE '%term%' through use_text_index_like_evaluation_by_dictionary_scan, support phrase search behind allow_experimental_text_index_phrase_search, and ship Japanese, Chinese and ICU tokenizers along with hasAnyTokens and hasAllTokens. Posting lists are decoded lazily by default, and the index works over JSON columns through JSONAllValues().

If you keep a separate search system only to filter logs or events by term, benchmark it against a text index on the ClickHouse table that already holds that data.

11. Use projections for a second sort order and materialized views for aggregates

Both spend write time to save read time, and they behave differently.

A projection lives inside the table. The planner picks it automatically, and it's sorted and written on every insert. Use one when a second set of queries needs a different ORDER BY over the same rows. Where insert latency matters more than fresh reads, materialize_projections_on_insert and materialize_projections_on_merge let you move that write cost to merge time. To confirm a projection is being used, set force_optimize_projection = 1, and the query will error if none matches. Add projections only for queries you already run.

An incremental materialized view runs its SELECT on each inserted block and sees only that block. An aggregate across blocks therefore needs an AggregatingMergeTree target and -State combinators, or you end up with one partial row per insert. Incremental views also fire only on the left-hand table of a join, so changes to the right-hand table never reach them. Refreshable materialized views recompute on a schedule instead, and REFRESH DEPENDS ON chains them together, which replaces a fair amount of external scheduling code.

Semi-structured data and changing rows

12. Use JSON for keys you can't predict, and give it type hints

The JSON type has been production-ready for over a year and suits payloads whose shape changes from row to row. Data that merely arrives as JSON is a different case. A flat path that you query belongs in a real column.

Where you do use JSON, add type hints for the paths you know:

CREATE TABLE app_logs
(
    id      UInt64,
    payload JSON(`ts` DateTime, `severity` LowCardinality(String))
)
ENGINE = MergeTree
ORDER BY id;

In ClickHouse's test, hints cut storage by 38% and query time by 26% compared with untyped JSON. Leave max_dynamic_paths at its default of 1024, because each distinct path becomes a subcolumn that's written and merged in every part, and SKIP the paths you never read. Paths beyond the limit go into a shared structure, so going over it slows things down gradually instead of breaking.

13. Choose between a merge engine and lightweight UPDATE on purpose

ReplacingMergeTree removes duplicates during background merges, so queries can see duplicates until a merge runs. You can read from it in two ways.

FINAL deduplicates for you, and its cost grows with the number of parts. On ClickHouse's 152-million-row table spread across nine unmerged parts it took 1.5 seconds, and about 0.4 seconds once consolidated to one part per partition. argMax folds deduplication into the aggregation and stays steadier whatever the merge state: 1.0 seconds unmerged and about 0.48 consolidated in the same test.

If you rely on FINAL, set min_age_to_force_merge_seconds = 600 and min_age_to_force_merge_on_partition_only = 1 on the table so older partitions merge down to a single part. Do this only on partitioned tables. On an unpartitioned one it asks for a single merge that keeps growing.

The other option is lightweight UPDATE, currently in beta. It writes patch parts instead of rewriting columns, takes about as long as an INSERT SELECT, and the change is visible straight away. It needs enable_block_number_column and enable_block_offset_column on the table and can't change primary or partition key columns. The docs also advise keeping a single update under about 10% of the table, and a steady stream of small updates will run into too many parts.

If a ReplacingMergeTree exists only to absorb the odd correction to otherwise append-only data, a plain MergeTree with lightweight UPDATE may be the simpler design. Prototype it before you build another merge-engine pipeline.

Running it in production

14. Watch parts, queries and merges in the system tables

Part count per partition gives the earliest warning, because most ingestion and partitioning mistakes show up there first:

SELECT table, partition, count() AS parts
FROM system.parts
WHERE active
GROUP BY table, partition
HAVING parts > 10
ORDER BY parts DESC;

system.query_log records each query's lifecycle: query_duration_ms, read_rows, read_bytes, memory_usage, exception details, and ProfileEvents for low-level counters. system.parts holds the physical layout, including whether each part is Wide or Compact. On a cluster, create_union_system_log_tables gives you union views across replicas, so you don't have to hand-write clusterAllReplicas over the system log tables.

Three newer tools are worth adopting. EXPLAIN ANALYZE runs the query and annotates the plan with measured timing and parallelism for each stage, which is the quickest way to confirm an optimization did what you expected. system.user_query_log lets developers see their own queries without access to the full log. system.documentation and the /schema endpoint make the reference manual and the schema browsable from inside the server.

15. Set resource limits before anyone needs them

ClickHouse keeps allocating memory for a query until the server runs out. One unbounded GROUP BY from a notebook can take down the process your application depends on, and nothing in the defaults prevents it. The risk grows once AI agents are querying production data, since an agent can write that GROUP BY as easily as a person can.

Put limits in settings profiles attached to roles, so they apply whether or not the person writing a query knows they exist. max_memory_usage caps a single query on one server, and max_memory_usage_for_user caps everything one user has running at once. max_execution_time stops long-running queries, with timeout_overflow_mode deciding whether to throw an error or return partial results. max_rows_to_read and max_bytes_to_read reject a query that would scan more than you intended.

CREATE SETTINGS PROFILE analysts SETTINGS
    max_memory_usage = 20000000000,
    max_execution_time = 120,
    max_bytes_before_external_group_by = 10000000000
TO analyst_role;

CREATE QUOTA analysts_hourly
    FOR INTERVAL 1 hour MAX read_rows = 100000000
TO analyst_role;

Two profiles usually cover it. Application traffic gets tight limits that fail fast, because a serving query that needs 20 GB is a bug. People and BI tools get looser limits plus max_bytes_before_external_group_by and max_bytes_before_external_sort, so a large aggregation spills to disk instead of failing. Quotas cover what per-query limits miss: each query is reasonable on its own, and the hundredth one that hour is the problem.

Where the cost shows up

Most of these decisions cost almost nothing to get right on day one and a great deal to fix later. A sort key, a partition scheme, a column type or a missing memory limit all look fine on a small table, because ClickHouse is fast enough to cover for them. They surface when the data grows or when someone runs the wrong query at the wrong moment, and by then the fix usually means rebuilding a table.

That's why the schema practices come first and deserve the most time. Settle the sort key, the types and the partitions against the queries you actually run, and set limits before the first incident. The system tables in practice 14 will tell you how the rest is holding up.

If you're setting up ClickHouse, or moving onto it from Snowflake, Redshift, BigQuery or Postgres, this is the ground our data layer and migrations work covers. Before anything moves, Dyno measures the workload, so decisions like the sort key are made against real queries. For one example, the Maxa case study covers 72 Snowflake tables moved into ClickHouse Cloud in four days. Or book an architecture review and we'll go through your schema with you.

About the author

Raja Meer Baz is a Data Engineer at Bonneville Data, where he works on ClickHouse deployments and migrations. An earlier version of this piece appeared on his Substack.

Sources

Benchmark figures are ClickHouse's own, from Top 10 best practices tips for ClickHouse (March 2026). Version and feature details come from the 26.3 through 26.7 release posts and the 26.8 LTS changelog. Postgres replication details come from Introducing WalShadow and the Managed Postgres beta announcement. Everything else links to the ClickHouse documentation where it's mentioned.

See what fast looks like on your stack.

A review of your current setup, with a phased path to ClickHouse that's live in weeks.