This skill analyzes ClickHouse table designs, partitions, ORDER BY keys, and materialized views to identify anti-patterns and optimization opportunities.
npx playbooks add skill altinity/skills --skill altinity-expert-clickhouse-schema
Answers "is this table designed the way ClickHouse wants it" from system.parts, system.tables, system.columns, system.parts_columns, system.data_skipping_indices and system.merge_tree_settings.
Run altinity-expert-clickhouse-connection first if the connection mode, cluster and time window are not yet established.
checks.sql — 10 checks: partition health audit, oversized partitions on collapsing engines, primary key analysis, column count, Nullable column audit, over-long table and column names, materialized view design issues, materialized view dependency chains, a table overview and the table-level MergeTree settings that shape all of the above.reference.md — background (settings, sizing, anti-patterns); read only when you need to explain a recommendation.; and start with a -- @check <id> <title> header; keep the id with its result.-- @requires: skip the statement when the named table is missing, when keeper is required and the server has no Keeper/ZooKeeper, or when the version condition is not met. List skipped ids with the reason.{cluster} as written when a cluster macro exists; otherwise apply the connection skill's rewrite rule. Any other {placeholder} is a template variable: substitute a real value first or skip the statement.UNKNOWN_IDENTIFIER, run DESCRIBE TABLE system.<table> and drop the missing column.severity column is the verdict for that row. Copy it; do not re-grade.Partition distribution for one table, to judge whether the partition key is too granular.
SELECT
partition,
count() AS parts,
sum(rows) AS total_rows,
formatReadableSize(sum(bytes_on_disk)) AS partition_size
FROM clusterAllReplicas('{cluster}', system.parts)
WHERE active AND database = '{database}' AND table = '{table}'
GROUP BY partition
ORDER BY partition DESC
LIMIT 100;
Column compression for one table, to find columns whose type or codec is wrong.
SELECT
name, type, compression_codec,
formatReadableSize(sum(data_compressed_bytes)) AS compressed,
formatReadableSize(sum(data_uncompressed_bytes)) AS uncompressed,
round(sum(data_uncompressed_bytes) / nullIf(sum(data_compressed_bytes), 0), 2) AS ratio
FROM clusterAllReplicas('{cluster}', system.columns)
WHERE database = '{database}' AND table = '{table}'
GROUP BY name, type, compression_codec
ORDER BY sum(data_compressed_bytes) DESC
LIMIT 50;
Data skipping indexes declared across one database.
SELECT database, table, name AS index_name, type, expr, granularity
FROM clusterAllReplicas('{cluster}', system.data_skipping_indices)
WHERE database = '{database}'
ORDER BY database, table;
DateTime64 with microsecond precision first, because every row gets its own value and the sparse index cannot prune.max_bytes_to_merge_at_max_space_in_pool can never merge into one part, so deduplication or aggregation never completes. The fix is a finer partition key, not a bigger pool.LowCardinality(String); sequential integers and timestamps benefit from Delta or DoubleDelta before ZSTD.issue column instead of severity. A JOIN in a materialized view fires only on the left table's inserts, so the right side silently goes stale. A materialized view without TO owns a hidden .inner table that cannot be altered or backed up independently.check, severity, object, evidence, recommendation; one row per finding, Critical first. Evidence quotes the numbers from the result rows.altinity-expert-clickhouse-ingestionaltinity-expert-clickhouse-mergesaltinity-expert-clickhouse-memoryaltinity-expert-clickhouse-index-analysisaltinity-expert-clickhouse-reportingaltinity-expert-clickhouse-mutationsWeekly roundup of top Claude Code skills, MCP servers, and AI coding tips.