Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

Back to skills

Clickhouse

ASecurity

Use when designing ClickHouse schemas or queries. Covers MergeTree engine selection, State/Merge aggregate combinators, materialized view patterns, system.query_log and system.parts introspection, and data type / insert gotchas.

2 stars
0 votes
0 copies
0 views
Added 9/19/2026
ai-agentsgosqldatabase

Works with

cli

Security Analysis

A100/100

Scanned 9/19/2026

Install to Claude Code

$npx -y skills add Mixard/fable-pack --skill clickhouse --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Clickhouse?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Clickhouse
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mixard-clickhouse/badge)](https://www.skillsdirectory.com/skills/mixard-clickhouse)

More formats (shields.io, HTML) on the badges page.

Download Zip
Files
SKILL.md
---
name: clickhouse
description: Use when designing ClickHouse schemas or queries. Covers MergeTree engine selection, State/Merge aggregate combinators, materialized view patterns, system.query_log and system.parts introspection, and data type / insert gotchas.
---

# ClickHouse

## MergeTree Engine Selection

- `MergeTree` -- default for raw event/fact tables.
- `ReplacingMergeTree` -- deduplication by ORDER BY key; duplicates removed only at merge time (queries may still see them until parts merge; `FINAL` forces it at query cost).
- `AggregatingMergeTree` -- stores partial aggregate states (`AggregateFunction(...)` columns), usually fed by a materialized view.

```sql
CREATE TABLE events (
    date Date,
    market_id String,
    volume UInt64,
    created_at DateTime
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(date)
ORDER BY (date, market_id);
```

Partitioning: by month or day, DATE-typed key, avoid high partition counts. ORDER BY: most-filtered columns first; column order affects both index usefulness and compression.

## State/Merge Combinators and Materialized Views

Aggregate states are written with `-State` functions and read back with the matching `-Merge` function. The MV target table declares `AggregateFunction` columns:

```sql
CREATE TABLE market_stats_hourly (
    hour DateTime,
    market_id String,
    total_volume AggregateFunction(sum, UInt64),
    total_trades AggregateFunction(count, UInt32),
    unique_users AggregateFunction(uniq, String)
) ENGINE = AggregatingMergeTree()
PARTITION BY toYYYYMM(hour)
ORDER BY (hour, market_id);

CREATE MATERIALIZED VIEW market_stats_hourly_mv
TO market_stats_hourly
AS SELECT
    toStartOfHour(timestamp) AS hour,
    market_id,
    sumState(amount) AS total_volume,
    countState() AS total_trades,
    uniqState(user_id) AS unique_users
FROM trades
GROUP BY hour, market_id;
```

Reading requires `-Merge` plus GROUP BY (a plain SELECT on state columns returns opaque binary):

```sql
SELECT hour, market_id,
    sumMerge(total_volume) AS volume,
    countMerge(total_trades) AS trades,
    uniqMerge(unique_users) AS users
FROM market_stats_hourly
WHERE hour >= now() - INTERVAL 24 HOUR
GROUP BY hour, market_id;
```

An MV with `TO table` only sees rows inserted after its creation; backfill history with a manual `INSERT INTO target SELECT ... -State ...`.

## Query Notes

- Filter on ORDER BY / partition key columns first so partition pruning and the primary index apply; a leading `LIKE '%...%'` or non-key filter scans everything.
- Percentiles: `quantile(0.95)(x)` (approximate, fast); `quantiles(0.5, 0.95, 0.99)(x)` for several at once; `quantileExact` when precision matters.
- `uniq()` is approximate; `uniqExact()` for exact counts at higher memory cost.
- `countIf(cond)` / `sumIf(x, cond)` replace `count(CASE WHEN ...)` patterns.

## Introspection

Slow queries:

```sql
SELECT query_id, user, query, query_duration_ms, read_rows, read_bytes, memory_usage
FROM system.query_log
WHERE type = 'QueryFinish'
  AND query_duration_ms > 1000
  AND event_time >= now() - INTERVAL 1 HOUR
ORDER BY query_duration_ms DESC
LIMIT 10;
```

Table sizes and part counts:

```sql
SELECT database, table,
    formatReadableSize(sum(bytes)) AS size,
    sum(rows) AS rows,
    count() AS parts,
    max(modification_time) AS latest_modification
FROM system.parts
WHERE active
GROUP BY database, table
ORDER BY sum(bytes) DESC;
```

## Data Types

- `LowCardinality(String)` for repeated string values (statuses, country codes, names with up to ~10k distinct values) -- large compression and speed win.
- Smallest integer type that fits (`UInt32` over `UInt64`); `Enum8/16` for fixed categorical sets.

## Gotchas

- Batch inserts: each INSERT creates a part; frequent single-row inserts cause "too many parts" errors. Batch thousands of rows per insert or use async_insert.
- Avoid `SELECT *` (column store reads every listed column) and `FINAL` in hot paths.
- Prefer denormalization over multi-way JOINs; the right side of a JOIN is materialized in memory.

Attribution

MixardMixard
View sourceMore from Mixard →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Ultra-compressed communication mode. Cuts token usage ~75% by speaking like caveman while keeping full technical accuracy. Supports intensity levels: lite, full (default), ultra, wenyan-lite, wenyan-full, wenyan-ultra. Use when user says "caveman mode", "talk like caveman", "use caveman", "less tokens", "be brief", or invokes /caveman. Also auto-triggers when token efficiency is requested.

1023331 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

686011 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3331 votes

catchup

Recovers prior coding-agent session context by running `catchup <agent> --since-compact`, which extracts a clean summary of a previous Codex, Claude Code, Antigravity, OpenCode, or Pi Agent session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", or asks to recover/summarize a previous session before continuing. Do NOT use for the current conversation, git history, or any non-agent log.

611 votes

math-skill

A comprehensive mathematical reasoning skill for AI assistants — handles arithmetic to research-level problems with rigorous step-by-step reasoning, systematic verification, and transparent uncertainty handling

381 votes
View all in ai-agents →