Setting the file. One moment.
Chapter 04 · Clickhouse Best Practices
Subchapter 4.25
rules/schema-partition-low-cardinality.mdMarkdown2 KBView on GitHub
Impact: HIGH
Too many distinct partition values create excessive data parts, eventually triggering “too many parts” errors. ClickHouse enforces limits via and settings.
max_parts_in_totalparts_to_throw_insertIncorrect (high cardinality partitioning):
-- High cardinality = too many partitions
CREATE TABLE events (...)
ENGINE = MergeTree()
PARTITION BY user_id -- Millions of partitions!
ORDER BY (timestamp);
-- Daily partitions can grow unbounded over years
CREATE TABLE logs (...)
ENGINE = MergeTree()
PARTITION BY toDate(timestamp) -- 3650 partitions over 10 years
ORDER BY (service, timestamp);Correct (bounded cardinality):
-- Monthly partitions = 12 per year, bounded cardinality
CREATE TABLE events (
timestamp DateTime,
event_type LowCardinality(String),
user_id UInt64
)
ENGINE = MergeTree()
PARTITION BY toStartOfMonth(timestamp)
ORDER BY (event_type, timestamp);Validation:
-- Check partition count and health
SELECT
partition,
count() as parts,
sum(rows) as rows,
formatReadableSize(sum(bytes_on_disk)) as size
FROM system.parts
WHERE table = 'events' AND active
GROUP BY partition
ORDER BY partition;
-- Warning signs: hundreds or thousands of partitions