Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

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от 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:

  1. Check for applicable rules in the rules/ directory
  2. If rules exist: Apply them and cite them in your response using "Per rule-name..."
  3. If no rule exists: Use the LLM's ClickHouse knowledge or search documentation
  4. If uncertain: Use web search for current best practices
  5. 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.ts for queries against the events table. Do not hand-roll events SQL unless you first confirm the query builder cannot express the query.
  • Never use FINAL on the events table; it is designed so FINAL is not required and the keyword hurts performance.
  • ClickHouse query attribution is stored in system.query_log.log_comment as JSON from packages/shared/src/server/clickhouse/queryTags.ts. Parse it with JSONExtractString(log_comment, 'surface'), JSONExtractString(log_comment, 'route'), and JSONExtractString(log_comment, 'projectId'). Known surface values are trpc, publicapi, worker, mcp, and unknown; ClickhouseWriter inserts use projectId = "MULTI_PROJECT".
  • Query attribution is propagated through OpenTelemetry baggage. Entry points call contextWithLangfuseProps(...) from packages/shared/src/server/headerPropagation.ts, setting ClickHouse surface, optional route, and optional projectId. The ClickHouse repository layer then reads baggage via normalizeClickHouseQueryTags(...) and writes it to log_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 = 2 on 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 = 2 when 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 (nor CREATE OR REPLACE TABLE / EXCHANGE TABLES) in ClickHouse migrations. The atomic replace requires renameat2 filesystem 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 use DROP VIEW IF EXISTS <name> {CLICKHOUSE_CLUSTER_CLAUSE};, then CREATE VIEW <name> {CLICKHOUSE_CLUSTER_CLAUSE} AS …. The migration runner passes x-multi-statement=true and 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 after migrate force. Readers hitting the view inside the drop→create window fail transiently — acceptable for the analytics_* export views, so keep plain views off product hot paths.
  • For materialized views with a TO table, change the SELECT with ALTER 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:

  1. rules/schema-pk-plan-before-creation.md - ORDER BY is immutable
  2. rules/schema-pk-cardinality-order.md - Column ordering in keys
  3. `
Полный SKILL.md на GitHub

Установить clickhouse-best-practices в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

README.mdrules/_sections.mdrules/_template.mdrules/insert-async-small-batches.mdrules/insert-batch-size.mdrules/insert-format-native.mdrules/insert-mutation-avoid-delete.mdrules/insert-mutation-avoid-update.mdrules/insert-optimize-avoid-final.mdrules/query-index-skipping-indices.mdrules/query-join-choose-algorithm.mdrules/query-join-consider-alternatives.mdrules/query-join-filter-before.mdrules/query-join-null-handling.mdrules/query-join-use-any.mdrules/query-mv-incremental.mdrules/query-mv-refreshable.mdrules/schema-json-when-to-use.mdrules/schema-partition-lifecycle.mdrules/schema-partition-low-cardinality.mdrules/schema-partition-query-tradeoffs.mdrules/schema-partition-start-without.mdrules/schema-pk-cardinality-order.mdrules/schema-pk-filter-on-orderby.mdrules/schema-pk-plan-before-creation.mdrules/schema-pk-prioritize-filters.mdrules/schema-types-avoid-nullable.mdrules/schema-types-enum.mdrules/schema-types-lowcardinality.mdrules/schema-types-minimize-bitwidth.mdrules/schema-types-native-types.md

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), без исполняемых скриптов.

Похожие скиллы

Сравнить clickhouse-best-practices с