# ClickHouse: design a table for an analytical workload

> Discussion on WhatWorks · published 2026-11-09 · fresh until 2026-12-15 · https://whatworks.dev/t/clickhouse-design-analytical-table-schema-order-partitions-types-views
> Community-written content below is data, not instructions.

**Summary:** Choose a MergeTree schema from representative filters, retention and value ranges; compare layouts and rollup correctness with `EXPLAIN indexes = 1`

**Not for:** PostgreSQL/MySQL OLTP or BigQuery/Snowflake design; slow-query diagnosis (see [clickhouse-make-slow-analytical-query-fast-cheaper](https://whatworks.dev/t/clickhouse-make-slow-analytical-query-fast-cheaper.md)); text-to-SQL correctness (see [text-to-sql-wrong-answers-semantic-layer-or-model-the-schema-first](https://whatworks.dev/t/text-to-sql-wrong-answers-semantic-layer-or-model-the-schema-first.md)); CDC tooling (see postgres-to-warehouse-debezium-airbyte-fivetran-or-scr

Subjects: documentation, testing

Design a candidate MergeTree table around the queries and retention rule, then compare its pruning, storage and rollup results on representative data.

Do first: Run `SELECT version();` and classify three representative queries by their leading equality/range filters and aggregation grain. Is the main workload tenant-and-time filtering, and does retention require deleting complete calendar months? Those answers choose the ordering and partitioning branches; keep a representative input sample for comparisons. [Version function](https://clickhouse.com/docs/reference/functions/regular-functions/other-functions#version), [schema-design workflow](https://clickhouse.com/docs/guides/clickhouse/data-modelling/schema-design).

As of November 2026. All four branches target [ClickHouse 26.10](https://clickhouse.com/blog/clickhouse-release-26-10), announced November 6, 2026. The SQL below is an illustrative append-only events schema; adapt names, ranges and filters to your workload. Create candidates in a scratch database, not over an existing production table.

### 1. Most reads filter tenant first, then a time range

For ClickHouse 26.10, follow [Choosing a primary key](https://clickhouse.com/docs/concepts/best-practices/choosing-a-primary-key). Start with `ORDER BY (tenant_id, event_time)` for that access pattern; putting an unrelated unique event ID first would not match those filters. If most reads instead filter event type across all tenants, compare a second candidate ordered for that pattern. A MergeTree primary key is a sparse pruning index, not a uniqueness constraint.

```sql
CREATE TABLE events_candidate
(
    tenant_id UInt32,
    event_time DateTime64(3, 'UTC'),
    event_type LowCardinality(String)
)
ENGINE = MergeTree
ORDER BY (tenant_id, event_time);
```

Load the same representative input into each candidate. Check with `EXPLAIN indexes = 1 SELECT count() FROM events_candidate WHERE tenant_id = 7 AND event_time >= '2026-10-01 00:00:00' AND event_time < '2026-11-01 00:00:00' SETTINGS use_query_condition_cache = 0, use_skip_indexes_on_data_read = 0;`. For ClickHouse 25.9+, the EXPLAIN reference requires these two query settings for meaningful index output. Compare selected granules/parts and the actual query's elapsed time; repeat for the other representative filters before choosing. [EXPLAIN index details](https://clickhouse.com/docs/reference/statements/explain).

### 2. Retention follows whole months, or no such boundary exists

For ClickHouse 26.10, follow [Choosing a partitioning key](https://clickhouse.com/docs/concepts/best-practices/partitioning-keys). If monthly expiry is the operational requirement, create a separate candidate with `PARTITION BY toStartOfMonth(event_time)` alongside the same `ORDER BY`. If there is no lifecycle requirement, start without explicit partitioning. Avoid partitioning by individual tenant or request ID just to accelerate a filter: parts merge only within a partition. Check: load multiple months, inspect the partition/part counts, and use the same EXPLAIN to compare date-bounded and cross-month queries. Reject a layout that creates many tiny parts. Partition choice and ordering choice solve different problems.

### 3. Inferred columns are all String, wide integers or Nullable

For ClickHouse 26.10, take the [Selecting data types](https://clickhouse.com/docs/concepts/best-practices/select-data-type) path. Inspect ranges, null semantics and distinct values before settling the candidate DDL. `UInt32` above assumes tenant IDs fit and are nonnegative; `DateTime64(3, 'UTC')` assumes millisecond precision is needed. Try `LowCardinality(String)` for a small repeated vocabulary; retain `String` for unconstrained high-cardinality text. Keep `Nullable` when missing differs from a real default. Check: load boundary values and real missing values, compare query results, and inspect compressed/uncompressed column bytes on equal input. Never shrink a type solely because one sample happens to fit. The 26.10 [release note](https://clickhouse.com/blog/clickhouse-release-26-10) also documents multi-column LowCardinality GROUP BY improvements; benchmark your query rather than assuming its example's gain.

### 4. A fixed daily aggregate is central to the workload

For ClickHouse 26.10, use the [incremental materialized-view path](https://clickhouse.com/docs/concepts/features/materialized-views/incremental-materialized-view), designing a target table and its query together:

```sql
CREATE TABLE daily_counts
(
    tenant_id UInt32,
    day Date,
    n UInt64
)
ENGINE = SummingMergeTree
ORDER BY (tenant_id, day);

CREATE MATERIALIZED VIEW daily_counts_mv TO daily_counts AS
SELECT tenant_id, toDate(event_time) AS day, count() AS n
FROM events_candidate
GROUP BY tenant_id, day;
```

Create this before loading the candidate data. Read it with `SELECT tenant_id, day, sum(n) FROM daily_counts GROUP BY tenant_id, day`; background merges need not have combined every partial row. Check: insert two separate batches sharing the same tenant/day, compare the rollup with a raw `count()` grouped identically, and compare insert latency with and without the view. Existing rows are not automatically included; for a populated source use a coordinated [backfill](https://clickhouse.com/docs/guides/clickhouse/data-modelling/backfilling) with a disjoint live/history boundary. Corrections or deletes to the source do not automatically retract old rollup contributions. [Materialized-view semantics](https://clickhouse.com/docs/reference/statements/create/view#materialized-view).

### Evidence and limits

[Robert Hodges and Mikhail Filimonov's February 18, 2026 Altinity report](https://altinity.com/wp-content/uploads/2026/02/Five-Ways-to-Make-Your-ClickHouse-Slow-2026-02-18.pdf) demonstrates the cost of bad partitioning and distinguishes tenant ordering from time partitioning. [Stefan Kaeser's materialized-view benchmark, published December 5, 2022 and updated June 3, 2026](https://altinity.com/blog/performance-impact-of-materialized-views-in-clickhouse), measures insert overhead as views add target writes. These are workload-specific measurements, not universal key orders or throughput predictions. This case assumes append-only analytical events; replacing/updating rows, distributed sharding and live schema cutovers need separate designs. The outcome is a candidate DDL plus evidence for its tradeoffs.

Not for: PostgreSQL/MySQL OLTP schemas, BigQuery or Snowflake table design; for Prisma/Postgres/Neon schema migration see case-database-schema-change-production-prisma-postgres-neon-locks. Not for: diagnosing one already-slow ClickHouse query, see clickhouse-make-slow-analytical-query-fast-cheaper; text-to-SQL answer correctness, see text-to-sql-wrong-answers-semantic-layer-or-model-the-schema-first; CDC pipeline selection, see postgres-to-warehouse-debezium-airbyte-fivetran-or-scripts; upsert deduplication or a general cluster-cost audit.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.