altinity-expert-clickhouse/skills/altinity-expert-clickhouse-reporting/SKILL.md
Diagnose ClickHouse SELECT query performance, analyze query patterns, identify slow queries, and find optimization opportunities. Use for query latency and timeout issues.
npx skillsauth add altinity/skills altinity-expert-clickhouse-reportingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Diagnose SELECT query performance issues, analyze query patterns, and identify optimization opportunities.
Run all queries from checks.sql in this skill's directory and analyze the results.
-- Check if data skipping indices exist
select
database,
table,
name as index_name,
type,
expr,
granularity
from system.data_skipping_indices
where database = '{database}' and table = '{table}'
For a specific slow query, check how many marks (granules) were read:
select
query_id,
read_rows,
selected_marks,
selected_parts,
formatReadableSize(read_bytes) as read_bytes,
round(read_rows / nullIf(selected_marks, 0)) as rows_per_mark
from system.query_log
where query_id = '{query_id}'
and type = 'QueryFinish'
High selected_marks relative to result = index not selective enough.
-- Always time-bound
where event_date >= today() - 1
-- or
where event_time > now() - interval 1 hour
-- Always limit
limit 100
-- Filter by type
where type = 'QueryFinish' -- completed
where type like 'Exception%' -- failed
-- By user
where user = 'analytics_user'
-- By query pattern
where query ilike '%SELECT%FROM my_table%'
-- By duration threshold
where query_duration_ms > 10000 -- > 10 seconds
-- By normalized hash (for specific query pattern)
where normalized_query_hash = 1234567890
| Finding | Load Module | Reason |
|---------|-------------|--------|
| High memory queries | altinity-expert-clickhouse-memory | Memory limits/optimization |
| Reading too many parts | altinity-expert-clickhouse-merges | Part consolidation |
| Poor index selectivity | altinity-expert-clickhouse-schema | Index/ORDER BY design |
| Cache misses | altinity-expert-clickhouse-caches | Cache sizing |
| MV slow | altinity-expert-clickhouse-ingestion | MV optimization |
| Setting | Scope | Notes |
|---------|-------|-------|
| max_execution_time | Query | Query timeout |
| max_rows_to_read | Query | Limit rows scanned |
| max_bytes_to_read | Query | Limit bytes scanned |
| max_threads | Query | Parallelism |
| use_query_cache | Query | Enable query result caching |
| log_queries | Server | Enable query logging |
| log_queries_min_query_duration_ms | Server | Log threshold |
tools
Read-only ClickHouse security audit expert for live or exported systems. Use when assessing ClickHouse security posture, reviewing users, roles, grants, settings profiles, row policies, table functions, external sources, table engines, executable UDFs, audit logs, named collections, password hash hygiene, SQL SECURITY DEFINER, impersonation, TLS/network exposure, Keeper/interserver security, encryption at rest, backups, the HTTP interface surface, cluster security, or version-specific ClickHouse security behavior. Diagnoses from SQL/system tables, supplied configuration files, query logs, access metadata, and ClickHouse/Altinity documentation.
tools
Diagnose and resolve ClickHouse grant and authentication errors, especially after upgrades. Use when queries fail with ACCESS_DENIED/NOT_ENOUGH_PRIVILEGES, AUTHENTICATION_FAILED/WRONG_PASSWORD/REQUIRED_PASSWORD, or ON CLUSTER privilege errors; when system.* or INFORMATION_SCHEMA access is denied; or when grant behavior changes after version upgrades.
tools
Profile a ClickHouse cluster via MCP and emit a per-cluster "analyst" Skill the user can save in claude.ai. Activate when the user asks to "profile this ClickHouse", "generate an analyst skill", "build a schema guide", "map the data in this cluster", or regenerate an existing cluster-analyst Skill after schema changes. Works against any ClickHouse with read-only SELECT/SHOW/DESCRIBE access via an `execute_query` MCP tool (e.g. the Altinity MCP server). Outputs a 5-file markdown bundle plus a README.
tools
Diagnose ClickHouse disk usage, compression efficiency, part sizes, and storage bottlenecks. Use for disk space issues and slow IO.