Automated summary
This skill prescribes ClickHouse (v24.4+) schema design and optimization, covering ORDER BY key selection, compression codecs, PARTITION BY, and performance accelerators.
Strengths
- Clear six-step workflow for designing or auditing a schema
- Precise ORDER BY key rules backed by a concrete anti-pattern showing 10x slower queries
- Per-column codec reference table, including when to prefer LZ4 over ZSTD
- Covers both ClickHouse Cloud (SharedMergeTree) and self-hosted (ReplicatedMergeTree) deployments
Limitations
- The provided document is truncated: the PARTITION BY section and audit scripts are not fully detailed
- Does not address query tuning or ingestion concerns such as batch sizing and async inserts
- Assumes prior familiarity with MergeTree engines and column cardinality analysis
Use it when creating a new ClickHouse table or when trying to cut query latency and disk usage on an existing schema.
Avoid it for diagnosing slow queries that need no schema change, or for other analytical engines like DuckDB or BigQuery.
Security analysis
CautionThe content is purely a ClickHouse schema-design guide: SQL examples, codec tables, and tuning advice. No destructive commands, credential access, network exfiltration, obfuscated payloads, or safety-disabling instructions appear. The only risk surface is the declared Bash tool and the referenced-but-missing scripts/ directory, which could contain arbitrary commands; that warrants 'caution' rather than 'safe' until those files are reviewed.
- •Declares Bash in allowed-tools; instructions reference running audit queries via scripts/, which implies executing local shell/SQL commands
- •References supporting files (scripts/, references/schema-documentation.md) that are not included in the submission, so their contents cannot be vetted
Examples
Design a ClickHouse MergeTree schema for a trades table with exchange, symbol, timestamp, trade_id, price and quantity. Pick the ORDER BY key and the compression codec for each column.My ClickHouse table orders by (trade_id, timestamp, symbol, exchange) and range queries are slow. Propose a better ORDER BY key and explain the tradeoff.Should I use ZSTD or LZ4 for my DateTime64 timestamp column in a read-heavy ClickHouse dashboard? Show the column definition.name: clickhouse-architect description: ClickHouse schema design and optimization. TRIGGERS - ClickHouse schema, compression codecs, MergeTree, ORDER BY tuning, partition key. allowed-tools: Read, Bash, Grep, Skill
ClickHouse Architect
<!-- ADR: 2025-12-09-clickhouse-architect-skill -->Prescriptive schema design, compression selection, and performance optimization for ClickHouse (v24.4+). Covers both ClickHouse Cloud (SharedMergeTree) and self-hosted (ReplicatedMergeTree) deployments.
Core Methodology
Schema Design Workflow
Follow this sequence when designing or reviewing ClickHouse schemas:
- Define ORDER BY key (3-5 columns, lowest cardinality first)
- Select compression codecs per column type
- Configure PARTITION BY for data lifecycle management
- Add performance accelerators (projections, indexes)
- Validate with audit queries (see scripts/)
- Document with COMMENT statements (see
references/schema-documentation.md)
ORDER BY Key Selection
The ORDER BY clause is the most critical decision in ClickHouse schema design.
Rules:
- Limit to 3-5 columns maximum (each additional column has diminishing returns)
- Place lowest cardinality columns first (e.g.,
tenant_idbeforetimestamp) - Include all columns used in WHERE clauses for range queries
- PRIMARY KEY must be a prefix of ORDER BY (or omit to use full ORDER BY)
Example:
-- Correct: Low cardinality first, 4 columns
CREATE TABLE trades (
exchange LowCardinality(String),
symbol LowCardinality(String),
timestamp DateTime64(3),
trade_id UInt64,
price Float64,
quantity Float64
) ENGINE = MergeTree()
ORDER BY (exchange, symbol, timestamp, trade_id);
-- Wrong: High cardinality first (10x slower queries)
ORDER BY (trade_id, timestamp, symbol, exchange);
Compression Codec Quick Reference
| Column Type | Default Codec | Read-Heavy Alternative | Example |
| ------------------------ | -------------------------- | ------------------------- | -------------------------------------------------- |
| DateTime/DateTime64 | CODEC(DoubleDelta, ZSTD) | CODEC(DoubleDelta, LZ4) | timestamp DateTime64(3) CODEC(DoubleDelta, ZSTD) |
| Float prices/gauges | CODEC(Gorilla, ZSTD) | CODEC(Gorilla, LZ4) | price Float64 CODEC(Gorilla, ZSTD) |
| Integer counters | CODEC(T64, ZSTD) | — | count UInt64 CODEC(T64, ZSTD) |
| Slowly changing integers | CODEC(Delta, ZSTD) | CODEC(Delta, LZ4) | version UInt32 CODEC(Delta, ZSTD) |
| String (low cardinality) | LowCardinality(String) | — | status LowCardinality(String) |
| General data | CODEC(ZSTD(3)) | CODEC(LZ4) | Default compression level 3 |
When to use LZ4 over ZSTD: LZ4 provides 1.76x faster decompression. Use LZ4 for read-heavy workloads with monotonic sequences (timestamps, counters). Use ZSTD (default) when compression ratio matters or data patterns are unknown.
Note on codec combinations:
Delta/DoubleDelta + Gorilla combinations are blocked by default (allow_suspicious_codecs) because Gorilla already performs implicit delta compression internally—combining them is redundant, not dangerous. A historical corruption bug (PR #45615, Jan 2023) was fixed, but the blocking remains as a best practice guardrail.
Use each codec family independently for its intended data type:
-- Correct usage
price Float64 CODEC(Gorilla, ZSTD) -- Floats: use Gorilla
timestamp DateTime64 CODEC(DoubleDelta, ZSTD) -- Timestamps: use DoubleDelta
timestamp DateTime64 CODEC(DoubleDelta, LZ4) -- Read-heavy: use LZ4
PARTITION BY Guidelines
PARTITION BY is for data lifecycle management, NOT query optimization.
Rules:
- Partition by time units (month, week) for TTL and data management
- Keep partition count under 1000 total across all tables
- Each partition should contain 1-300 parts maximum
- Never partition by high-cardinality columns
Example:
-- Correct: Monthly partitions for TTL management
PARTITION BY toYYYYMM(timestamp)
-- Wrong: Daily partitions (too many parts)
PARTITION BY toYYYYMMDD(timestamp)
-- Wrong: High-cardinality partition key
PARTITION BY user_id
Anti-Patterns Checklist (v24.4+)
| Pattern | Severity | Modern Status | Fix |
| ------------------------------- | -------- | ------------------ | ------------------------------------- |
| Too many parts (>300/partition) | Critical | Still critical | Reduce partition granularity |
| Small batch inserts (<1000) | Critical | Still critical | Batch to 10k-100k rows |
| High-cardinality first ORDER BY | Critical | Still critical | Reorder: lowest cardinality first |
| No memory limits | High | Still critical | Set max_memory_usage |
| Denormalization overuse | High | Still critical | Use dictionaries + materialized views |
| Large JOINs | Medium | 180x improved | Still avoid for ultra-low-latency |
| Mutations (UPDATE/DELETE) | Medium | 1700x improved | Use lightweight updates (v24.4+) |
Table Engine Selection
| Deployment | Engine | Use Case |
| ------------------- | --------------------- | ------------------------------- |
| ClickHouse Cloud | SharedMergeTree | Default for cloud deployments |
| Self-hosted cluster | ReplicatedMergeTree | Multi-node with replication |
| Self-hosted single | MergeTree | Single-node development/testing |
Cloud (SharedMergeTree):
CREATE TABLE trades (...)
ENGINE = SharedMergeTree('/clickhouse/tables/{shard}/trades', '{replica}')
ORDER BY (exchange, symbol, timestamp);
Self-hosted (ReplicatedMergeTree):
CREATE TABLE trades (...)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/trades', '{replica}')
ORDER BY (exchange, symbol, timestamp);
Skill Delegation Guide
<!-- ADR: 2025-12-10-clickhouse-skill-delegation -->This skill is the hub for ClickHouse-related tasks. When the user's needs extend beyond schema design, invoke the related skills below.
Delegation Decision Matrix
| User Need | Invoke Skill | Trigger Phrases |
| ----------------------------------------------- | ------------------------------------------ | ---------------------------------------------------- |
| Create database users, manage permissions | devops-tools:clickhouse-cloud-management | "create user", "GRANT", "permissions", "credentials" |
| Configure DBeaver, generate connection JSON | devops-tools:clickhouse-pydantic-config | "DBeaver", "client config", "connection setup" |
| Validate schema contracts against live database | quality-tools:schema-e2e-validation | "validate schema", "Earthly E2E", "schema contract" |
Typical Workflow Sequence
- Schema Design (THIS SKILL) → Design ORDER BY, compression, partitioning
- User Setup →
clickhouse-cloud-management(if cloud credentials needed) - Client Config →
clickhouse-pydantic-config(generate DBeaver JSON) - Validation →
schema-e2e-validation(CI/CD schema contracts)
Example: Full Stack Request
User: "I need to design a trades table for ClickHouse Cloud and set up DBeaver to query it."
Expected behavior:
- Use THIS skill for schema design
- Invoke
clickhouse-cloud-managementfor creating database user - Invoke
clickhouse-pydantic-configfor DBeaver configuration
Performance Accelerators
Projections
Create alternative sort orders that ClickHouse automatically selects:
ALTER TABLE trades ADD PROJECTION trades_by_symbol (
SELECT * ORDER BY symbol, timestamp
);
ALTER TABLE trades MATERIALIZE PROJECTION trades_by_symbol;
Materialized Views
Pre-compute aggregations for dashboard queries:
CREATE MATERIALIZED VIEW trades_hourly_mv
ENGINE = SummingMergeTree()
ORDER BY (exchange, symbol, hour)
AS SELECT
exchange,
symbol,
toStartOfHour(timestamp) AS hour,
sum(quantity) AS total_volume,
count() AS trade_count
FROM trades
GROUP BY exchange, symbol, hour;
Dictionaries
Replace JOINs with O(1) dictionary lookups for large-scale star schemas:
When to use dictionaries (v24.4+):
- Fact tables with 100M+ rows joining dimension tables
- Dimension tables 1k-500k rows with monotonic keys
- LEFT ANY JOIN semantics required
When JOINs are sufficient (v24.4+):
- Dimension tables <500 rows (JOIN overhead negligible)
- v24.4+ predicate pushdown provides 8-180x improvements
- Complex JOIN types (FULL, RIGHT, multi-condition)
Benchmark context: 6.6x speedup measured on Star Schema Benchmark (1.4B rows).
CREATE DICTIONARY symbol_info (
symbol String,
name String,
sector String
)
PRIMARY KEY symbol
SOURCE(CLICKHOUSE(TABLE 'symbols'))
LAYOUT(FLAT()) -- Best for <500k entries with monotonic keys
LIFETIME(3600);
-- Use in queries (O(1) lookup)
SELECT
symbol,
dictGet('symbol_info', 'name', symbol) AS symbol_name
FROM trades;
Scripts
Execute comprehensive schema audit:
clickhouse-client --multiquery < scripts/schema-audit.sql
The audit script checks:
- Part count per partition (threshold: 300)
- Compression ratios by column
- Query performance patterns
- Replication lag (if applicable)
- Memory usage patterns
Additional Resources
Reference Files
| Reference | Content |
| ------------------------------------------------------------------------------------------ | ---------------------------------------------- |
| references/schema-design-workflow.md | Complete workflow with examples |
| references/compression-codec-selection.md | Decision tree + benchmarks |
| references/anti-patterns-and-fixes.md | 13 deadly sins + v24.4+ status |
| references/audit-and-diagnostics.md | Query interpretation guide |
| references/idiomatic-architecture.md | Parameterized views, dictionaries, dedup |
| references/schema-documentation.md | COMMENT patterns + naming for AI understanding |
External Documentation
Python Driver Policy
<!-- ADR: 2025-12-10-clickhouse-python-driver-policy -->Use clickhouse-connect (official) for all Python integrations.
# ✅ RECOMMENDED: clickhouse-connect (official, HTTP)
import clickhouse_connect
client = clickhouse_connect.get_client(
host='localhost',
port=8123, # HTTP port
username='default',
password=''
)
result = client.query("SELECT * FROM trades LIMIT 1000")
df = client.query_df("SELECT * FROM trades") # Pandas integration
Why NOT clickhouse-driver
| Factor | clickhouse-connect | clickhouse-driver | | --------------- | ------------------ | ------------------- | | Maintainer | ClickHouse Inc. | Solo developer | | Weekly commits | Yes (active) | Sparse (months) | | Open issues | 41 (addressed) | 76 (accumulating) | | Downloads/week | 2.7M | 1.5M | | Bus factor risk | Low (company) | High (1 person) |
Do NOT use clickhouse-driver despite its ~26% speed advantage for large exports. The maintenance risk outweighs performance gains:
- Single maintainer (mymarilyn) with no succession plan
- Issues accumulating without response
- Risk of abandonment breaks production code
Exception: Only consider clickhouse-driver if you have extreme performance requirements (exporting millions of rows) AND accept the maintenance risk.
Related Skills
| Skill | Purpose |
| ------------------------------------------ | ----------------------------- |
| devops-tools:clickhouse-cloud-management | User/permission management |
| devops-tools:clickhouse-pydantic-config | DBeaver connection generation |
| quality-tools:schema-e2e-validation | YAML schema contracts |
| quality-tools:multi-agent-e2e-validation | Database migration validation |
From the file to a first result
The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.
View the source and supporting filesThis download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.
1. Download the file
Download SKILL.mdFrom the root of a test project, save the file as .skill-downloads/clickhouse-architect-mmlj2o83/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.
Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.
mkdir -p '.skill-downloads/clickhouse-architect-mmlj2o83' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/clickhouse-architect-mmlj2o83/download' --output '.skill-downloads/clickhouse-architect-mmlj2o83/SKILL.md.part' && mv '.skill-downloads/clickhouse-architect-mmlj2o83/SKILL.md.part' '.skill-downloads/clickhouse-architect-mmlj2o83/SKILL.md'2. Check prerequisites
Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.
Tools declared by the author (check availability in your agent): Read, Bash, Grep, Skill
No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.
The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.
3. Load the skill
After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.
Claude Code
test -f '.skill-downloads/clickhouse-architect-mmlj2o83/SKILL.md' && test -s '.skill-downloads/clickhouse-architect-mmlj2o83/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/clickhouse-architect' && cp -R '.skill-downloads/clickhouse-architect-mmlj2o83' '.claude/skills/clickhouse-architect'Cursor
test -f '.skill-downloads/clickhouse-architect-mmlj2o83/SKILL.md' && test -s '.skill-downloads/clickhouse-architect-mmlj2o83/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/clickhouse-architect' && cp -R '.skill-downloads/clickhouse-architect-mmlj2o83' '.cursor/skills/clickhouse-architect'OpenSkills
OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.
Official OpenSkills installationopenskills install './.skill-downloads/clickhouse-architect-mmlj2o83'openskills read 'clickhouse-architect-mmlj2o83'Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.
For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.
openskills syncManual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.
4. Try a first task
Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:
Read .skill-downloads/clickhouse-architect-mmlj2o83/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.
Create Interactive Maps with kepler.gl
Data & AI
Create interactive map visualizations and export standalone HTML using the keplergl Python package. Use to plot geospatial data from DataFrames, GeoJSON, or CSV.
Agent-Driven Parameter Optimization
Data & AI
Guide for optimizing configurable systems with a measurable objective, using bounded trials and evidence-based recommendations.
ICP Visitor Outreach
Data & AI
Identify signed-up users matching the ideal customer profile but stalled, and draft personalized outreach to re-engage them.