clickhouse-best-practices
БесплатноБез исполняемых скриптовНе проверенMUST USE when reviewing ClickHouse schemas, queries, or configurations. Contains 28 rules that MUST be checked before providing recommendations. Always read…
от langfuse★ 38 069 звёзд на GitHubОб этом скилле
ClickHouse Best Practices
Comprehensive guidance for ClickHouse covering schema design, query optimization, and data ingestion. Contains 28 rules across 3 main categories (schema, query, insert), prioritized by impact.
Official docs: ClickHouse Best Practices
IMPORTANT: How to Apply This Skill
Before answering ClickHouse questions, follow this priority order:
- Check for applicable rules in the
rules/directory - If rules exist: Apply them and cite them in your response using "Per
rule-name..." - If no rule exists: Use the LLM's ClickHouse knowledge or search documentation
- If uncertain: Use web search for current best practices
- Always cite your source: rule name, "general ClickHouse guidance", or URL
Why rules take priority: ClickHouse has specific behaviors (columnar storage, sparse indexes, merge tree mechanics) where general database intuition can be misleading. The rules encode validated, ClickHouse-specific guidance.
Langfuse-Specific Rules
- Use
packages/shared/src/server/queries/clickhouse-sql/event-query-builder.tsfor queries against theeventstable. Do not hand-rolleventsSQL unless you first confirm the query builder cannot express the query. - Never use
FINALon theeventstable; it is designed soFINALis not required and the keyword hurts performance. - ClickHouse query attribution is stored in
system.query_log.log_commentas JSON frompackages/shared/src/server/clickhouse/queryTags.ts. Parse it withJSONExtractString(log_comment, 'surface'),JSONExtractString(log_comment, 'route'), andJSONExtractString(log_comment, 'projectId'). Knownsurfacevalues aretrpc,publicapi,worker,mcp, andunknown; ClickhouseWriter inserts useprojectId = "MULTI_PROJECT". - Query attribution is propagated through OpenTelemetry baggage. Entry points
call
contextWithLangfuseProps(...)frompackages/shared/src/server/headerPropagation.ts, setting ClickHousesurface, optionalroute, and optionalprojectId. The ClickHouse repository layer then reads baggage vianormalizeClickHouseQueryTags(...)and writes it tolog_comment. Prefer setting attribution at entry points rather than passing tags through every repository call. packages/shared/clickhouse/migrations/canonical/**is the single canonical template tree rendered for clustered and unclustered installs. Put{CLICKHOUSE_CLUSTER_CLAUSE}at every cluster-aware DDL position. Use{CLICKHOUSE_REPLICATION_PREFIX}only for engines that deliberately differ by mode; some tables intentionally stay non-replicated in both modes.- In new migrations, put literal
SETTINGS alter_sync = 2on column and index metadata ALTERs for tables that can be replicated. Unclustered migration SQL can run against replicated tables. A later ALTER on the same table can reach a replica that still has the old schema, even across migration files or during rollback. - Use
mutations_sync = 2when a later step needs a mutation to finish. Keep intentionally deferred index builds asynchronous. - For shipped migrations, change historical SQL only for a verified fix. Check the rendered diff in both modes before updating a frozen checksum.
- Never use
CREATE OR REPLACE VIEW(norCREATE OR REPLACE TABLE/EXCHANGE TABLES) in ClickHouse migrations. The atomic replace requiresrenameat2filesystem support, which NFS-backed self-hosted deployments (e.g. ClickHouse data on AWS EFS) lack — the migration fails and the deployment aborts on startup (GitHub issue #14906). Redefine a plain view as two statements in the same migration file. First useDROP VIEW IF EXISTS <name> {CLICKHOUSE_CLUSTER_CLAUSE};, thenCREATE VIEW <name> {CLICKHOUSE_CLUSTER_CLAUSE} AS …. The migration runner passesx-multi-statement=trueand golang-migrate splits files on;without parsing SQL, so keep semicolons out of comments and string literals. Keep every statement idempotent (IF EXISTS/IF NOT EXISTS) so a dirty, half-applied migration can be re-run aftermigrate force. Readers hitting the view inside the drop→create window fail transiently — acceptable for theanalytics_*export views, so keep plain views off product hot paths. - For materialized views with a
TOtable, change the SELECT withALTER TABLE <mv> {CLICKHOUSE_CLUSTER_CLAUSE} MODIFY QUERY <select>. Dropping and recreating a live view loses rows inserted in between. When the new SELECT reads or writes new columns, wait for both the source and destination ALTERs before switching the query. A stale destination can accept an insert and silently omit the new fields.
Review Procedures
For Schema Reviews (CREATE TABLE, ALTER TABLE)
Read these rule files in order:
rules/schema-pk-plan-before-creation.md- ORDER BY is immutablerules/schema-pk-cardinality-order.md- Column ordering in keys- `
Установить clickhouse-best-practices в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл clickhouse-best-practices?
MUST USE when reviewing ClickHouse schemas, queries, or configurations. Contains 28 rules that MUST be checked before providing recommendations. Always read relevant rule files and cite specific rules in responses.
Как установить скилл clickhouse-best-practices?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл clickhouse-best-practices запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
agent-skill-stack
Find, evaluate, and assemble the smallest compatible set of AI Agent Skills for an end-to-end natural-language goal. Use when a user wants Skills for a…
от GitHubbuild-evidence-map
Build an auditable evidence map for a contested technical choice, research synthesis, proposal review, or consequential decision. Use when Copilot must…
от GitHubpinecone-rag
Build production RAG pipelines and persistent agent memory using Pinecone as the vector database backend. ALWAYS USE THIS SKILL when the user mentions…
от GitHubqdrant-monitoring-debugging
Diagnoses Qdrant production issues using metrics and observability tools. Use when someone reports 'optimizer stuck', 'indexing too slow', 'memory too high'…
от GitHub