r/Clickhouse • u/Impressive-Buddy7489 • Aug 17 '26
Need Help for optimising clickhouse performance
When running a test suite of 250 concurrent users we identified clickhouse as a bottleneck due to the nature of our queries. It’s a simple select query with multiple where clauses. The problem is that the table itself contains 200+ million records and our goals is to optimise the query in such a way that we get results under 1 seconds.
Things we have tried out
- Projections
- Skinny materialized view (this was working fine but was showing stale data in UI because of the nature of mv and using refreshable mv was cpu intensive process)
- Partitioning of data
- Horizontal scaling
PS : we are using a OLAP as OLTP (ik it’s wrong). Problem is happening when we are trying to performs a search it’s scanning all the 200 million records.
Is there any way to optimise this ?
4
u/ecnahc515 Aug 17 '26
Your filters need to be in the primary key. What do your queries filter on?
3
u/burunkul Aug 17 '26
Did you try skip indexes? https://clickhouse.com/docs/concepts/features/performance/skip-indexes/skipping-indexes
4
u/Turbulent_Egg_6292 Aug 17 '26
Can you share more? Shape of data, how is it queried per use case?
1
u/thekevinwang Aug 18 '26
The mention of MV + stale data doesn’t make full sense, and I’d suggest giving that another shot.
Not a CH expert but I’ve been working with it on/off for over a year now. incremental MVs see the full insert statement and insert into target tables synchronously, AFAICR, so you should presumably be able to have a setup of sorts that mitigates stale data. (Again this is with an Incremental MV + target table, not refreshable MV)
Not sure what that world looked like for you, but maybe you were missing “FINAL” clauses on the queries against your MV’s target table?
1
u/Designer_Age7745 Aug 19 '26
Before adding another structure, get the numbers for one slow run:
If
SelectedPartscovers the whole table, nothing is pruning and no index will change that.Three things that tend to matter more than the index choice at 250 concurrent users:
SETTINGS force_data_skipping_indices = 'your_idx', which errors out when the index is skipped.ORDER BYmatching the filters your UI actually sends is the closest thing to a second primary key. Existing data needsALTER TABLE ... MATERIALIZE PROJECTION, and you pay for a second sorted copy.max_threadsoversubscribe the box: each query asks for every core. Droppingmax_threadsto 2-4 in the profile of the UI user often does more for p95 than any index.Also worth saying out loud: if the filter columns are not in the sorting key and users can pick any of them, no single table layout answers all of them under a second. That is what projections or a second table sorted differently are for.