Install any skill in seconds. Free to start, no credit card required.
Get Started Free →ClickHouse database patterns, query optimization, analytics, and data engineering best practices for high-performance analytical workloads.
.claude/skills/clickhouse-io/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-13 | ✗→✓ | ▲ Improved | 121% | 0% |
| case-18 | ✗→✓ | ▲ Improved | 91% | 0% |
| case-19 | ✗→✓ | ▲ Improved | 60% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 102% | 0% |
| case-07 | ✓→✓ | = Same ✓ | 69% | 0% |
ClickHouse-specific patterns for high-performance analytics and data engineering.
ClickHouse is a column-oriented database management system (DBMS) for online analytical processing (OLAP). It's optimized for fast analytical queries on large datasets.
Key Features:
sqlCREATE TABLE markets_analytics ( date Date, market_id String, market_name String, volume UInt64, trades UInt32, unique_traders UInt32, avg_trade_size Float64, created_at DateTime ) ENGINE = MergeTree() PARTITION BY toYYYYMM(date) ORDER BY (date, market_id) SETTINGS index_granularity = 8192;
sql-- For data that may have duplicates (e.g., from multiple sources) CREATE TABLE user_events ( event_id String, user_id String, event_type String, timestamp DateTime, properties String ) ENGINE = ReplacingMergeTree() PARTITION BY toYYYYMM(timestamp) ORDER BY (user_id, event_id, timestamp) PRIMARY KEY (user_id, event_id);
sql-- For maintaining aggregated metrics 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); -- Query aggregated data 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 >= toStartOfHour(now() - INTERVAL 24 HOUR) GROUP BY hour, market_id ORDER BY hour DESC;
sql-- PASS: GOOD: Use indexed columns first SELECT * FROM markets_analytics WHERE date >= '2025-01-01' AND market_id = 'market-123' AND volume > 1000 ORDER BY date DESC LIMIT 100; -- FAIL: BAD: Filter on non-indexed columns first SELECT * FROM markets_analytics WHERE volume > 1000 AND market_name LIKE '%election%' AND date >= '2025-01-01';
sql-- PASS: GOOD: Use ClickHouse-specific aggregation functions SELECT toStartOfDay(created_at) AS day, market_id, sum(volume) AS total_volume, count() AS total_trades, uniq(trader_id) AS unique_traders, avg(trade_size) AS avg_size FROM trades WHERE created_at >= today() - INTERVAL 7 DAY GROUP BY day, market_id ORDER BY day DESC, total_volume DESC; -- PASS: Use quantile for percentiles (more efficient than percentile) SELECT quantile(0.50)(trade_size) AS median, quantile(0.95)(trade_size) AS p95, quantile(0.99)(trade_size) AS p99 FROM trades WHERE created_at >= now() - INTERVAL 1 HOUR;
sql-- Calculate running totals SELECT date, market_id, volume, sum(volume) OVER ( PARTITION BY market_id ORDER BY date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) AS cumulative_volume FROM markets_analytics WHERE date >= today() - INTERVAL 30 DAY ORDER BY market_id, date;
typescriptimport { createClient } from '@clickhouse/client' const clickhouse = createClient({ url: process.env.CLICKHOUSE_URL ?? 'http://localhost:8123', username: process.env.CLICKHOUSE_USER, password: process.env.CLICKHOUSE_PASSWORD }) // PASS: Batch insert (efficient) async function bulkInsertTrades(trades: Trade[]) { await clickhouse.insert({ table: 'trades', values: trades.map(trade => ({ id: trade.id, market_id: trade.market_id, user_id: trade.user_id, amount: trade.amount, timestamp: trade.timestamp.toISOString() })), format: 'JSONEachRow' }) } // FAIL: Individual inserts (slow) async function insertTrade(trade: Trade) { // Don't do this in a loop! await clickhouse.insert({ table: 'trades', values: [{ id: trade.id, market_id: trade.market_id, user_id: trade.user_id, amount: trade.amount, timestamp: trade.timestamp.toISOString() }], format: 'JSONEachRow' }) }
typescript// For continuous data ingestion import { Readable } from 'node:stream' async function streamInserts(dataSource: AsyncIterable<Record<string, unknown>>) { await clickhouse.insert({ table: 'trades', values: Readable.from(dataSource, { objectMode: true }), format: 'JSONEachRow' }) }
sql-- Create materialized view for hourly stats 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; -- Query the materialized view 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;
sql-- Check slow queries 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;
sql-- Check table sizes SELECT database, table, formatReadableSize(sum(bytes)) AS size, sum(rows) AS rows, max(modification_time) AS latest_modification FROM system.parts WHERE active GROUP BY database, table ORDER BY sum(bytes) DESC;
sql-- Daily active users SELECT toDate(timestamp) AS date, uniq(user_id) AS daily_active_users FROM events WHERE timestamp >= today() - INTERVAL 30 DAY GROUP BY date ORDER BY date; -- Retention analysis SELECT signup_date, countIf(days_since_signup = 0) AS day_0, countIf(days_since_signup = 1) AS day_1, countIf(days_since_signup = 7) AS day_7, countIf(days_since_signup = 30) AS day_30 FROM ( SELECT user_id, min(toDate(timestamp)) AS signup_date, toDate(timestamp) AS activity_date, dateDiff('day', signup_date, activity_date) AS days_since_signup FROM events GROUP BY user_id, activity_date ) GROUP BY signup_date ORDER BY signup_date DESC;
sql-- Conversion funnel SELECT countIf(step = 'viewed_market') AS viewed, countIf(step = 'clicked_trade') AS clicked, countIf(step = 'completed_trade') AS completed, round(clicked / viewed * 100, 2) AS view_to_click_rate, round(completed / clicked * 100, 2) AS click_to_completion_rate FROM ( SELECT user_id, session_id, event_type AS step FROM events WHERE event_date = today() ) GROUP BY session_id;
sql-- User cohorts by signup month SELECT toStartOfMonth(signup_date) AS cohort, toStartOfMonth(activity_date) AS month, dateDiff('month', cohort, month) AS months_since_signup, count(DISTINCT user_id) AS active_users FROM ( SELECT user_id, min(toDate(timestamp)) OVER (PARTITION BY user_id) AS signup_date, toDate(timestamp) AS activity_date FROM events ) GROUP BY cohort, month, months_since_signup ORDER BY cohort, months_since_signup;
typescript// Extract, Transform, Load async function etlPipeline() { // 1. Extract from source const rawData = await extractFromPostgres() // 2. Transform const transformed = rawData.map(row => ({ date: new Date(row.created_at).toISOString().split('T')[0], market_id: row.market_slug, volume: parseFloat(row.total_volume), trades: parseInt(row.trade_count) })) // 3. Load to ClickHouse await bulkInsertToClickHouse(transformed) } // Run periodically setInterval(etlPipeline, 60 * 60 * 1000) // Every hour
typescript// Listen to PostgreSQL changes and sync to ClickHouse import { Client } from 'pg' const pgClient = new Client({ connectionString: process.env.DATABASE_URL }) pgClient.query('LISTEN market_updates') pgClient.on('notification', async (msg) => { const update = JSON.parse(msg.payload) await clickhouse.insert({ table: 'market_updates', values: [ { market_id: update.id, event_type: update.operation, // INSERT, UPDATE, DELETE timestamp: new Date(), data: JSON.stringify(update.new_data) } ], format: 'JSONEachRow' }) })
Remember: ClickHouse excels at analytical workloads. Design tables for your query patterns, batch inserts, and leverage materialized views for real-time aggregations.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | pass→pass | 14,743 | 12,690 | -14% | 1 | 1 | 0% | 2,756 | 5,560 | +102% | 0 | 0 | — |
case-07 | pass→pass | 13,359 | 8,102 | -39% | 1 | 1 | 0% | 2,679 | 4,524 | +69% | 0 | 0 | — |
case-21 | pass→pass | 16,130 | 12,420 | -23% | 1 | 1 | 0% | 2,925 | 5,357 | +83% | 0 | 0 | — |
case-22 | pass→pass | 12,851 | 9,999 | -22% | 1 | 1 | 0% | 2,456 | 4,923 | +100% | 0 | 0 | — |
case-02 | pass→pass | 13,601 | 10,340 | -24% | 1 | 1 | 0% | 2,484 | 4,896 | +97% | 0 | 0 | — |
case-03 | pass→pass | 15,186 | 10,663 | -30% | 1 | 1 | 0% | 2,653 | 4,791 | +81% | 0 | 0 | — |
case-04 | pass→pass | 13,756 | 8,397 | -39% | 1 | 1 | 0% | 2,464 | 4,638 | +88% | 0 | 0 | — |
case-05 | pass→pass | 15,530 | 11,503 | -26% | 1 | 1 | 0% | 2,957 | 5,340 | +81% | 0 | 0 | — |
case-06 | pass→pass | 11,233 | 6,562 | -42% | 1 | 1 | 0% | 2,188 | 4,396 | +101% | 0 | 0 | — |
case-08 | pass→pass | 4,879 | 3,802 | -22% | 1 | 1 | 0% | 924 | 3,790 | +310% | 0 | 0 | — |
case-09 | pass→pass | 15,353 | 10,142 | -34% | 1 | 1 | 0% | 2,552 | 4,719 | +85% | 0 | 0 | — |
case-10 | pass→pass | 7,600 | 6,182 | -19% | 1 | 1 | 0% | 1,351 | 4,100 | +203% | 0 | 0 | — |
case-11 | fail→fail | 15,765 | 12,458 | -21% | 1 | 1 | 0% | 3,366 | 5,922 | +76% | 0 | 0 | — |
case-12 | pass→pass | 15,613 | 9,401 | -40% | 1 | 1 | 0% | 2,679 | 4,466 | +67% | 0 | 0 | — |
case-13 | fail→pass | 12,363 | 10,699 | -13% | 1 | 1 | 0% | 2,239 | 4,937 | +121% | 0 | 0 | — |
case-14 | pass→pass | 10,094 | 10,815 | +7% | 1 | 1 | 0% | 1,831 | 4,615 | +152% | 0 | 0 | — |
case-15 | fail→fail | 14,266 | 11,295 | -21% | 1 | 1 | 0% | 2,633 | 5,021 | +91% | 0 | 0 | — |
case-16 | pass→pass | 9,104 | 8,108 | -11% | 1 | 1 | 0% | 1,778 | 4,844 | +172% | 0 | 0 | — |
case-17 | fail→fail | 17,102 | 14,806 | -13% | 1 | 1 | 0% | 3,099 | 5,932 | +91% | 0 | 0 | — |
case-18 | fail→pass | 14,040 | 10,531 | -25% | 1 | 1 | 0% | 2,642 | 5,034 | +91% | 0 | 0 | — |
case-19 | fail→pass | 11,604 | 3,663 | -68% | 1 | 1 | 0% | 2,311 | 3,688 | +60% | 0 | 0 | — |
case-20 | pass→pass | 13,569 | 8,415 | -38% | 1 | 1 | 0% | 2,416 | 4,526 | +87% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +14 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
| Model | Method | Date | Lift |
|---|---|---|---|
| gemini-3.6-flash | verified | 7/27/2026 | 0% |
Other measured skills in the registry, with their headline benchmark lift.