Skip to content
Databases
Skill

/clickhouse-best-practices

MUST USE when reviewing ClickHouse schemas, queries, native full-text search, or configurations. Contains 36 rules that MUST be checked before providing recommendations. Always read relevant rule files and cite specific rules in responses.

From plugin
clickhouse-best-practices
57211 skills

Claude Code

$ npx -y skills add clickhouse/agent-skills --skill clickhouse-best-practices --agent claude-code

SKILL.md

clickhouse-best-practices.SKILL.md
name: clickhouse-best-practices
description: MUST USE when reviewing ClickHouse schemas, queries, native full-text search, or configurations. Contains 36 rules that MUST be checked before providing recommendations. Always read relevant rule files and cite specific rules in responses.
license: Apache-2.0
metadata:
  author: ClickHouse Inc
  version: "0.5.0"

ClickHouse Best Practices

Comprehensive guidance for ClickHouse covering schema design, query optimization, data ingestion, and AI agent connectivity. Contains 36 rules across 4 main categories (schema, query, insert, agent), prioritized by impact.

> **Official docs:** [ClickHouse Best Practices](https://clickhouse.com/docs/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 rules that match the deployed ClickHouse version and cite them using "Per `rule-name`...". Verify evolving features against version-specific official documentation; do not override newer authoritative evidence with an older rule. 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.

---

Agent Connectivity & Query Workflow

Before querying ClickHouse, agents must establish a connection and follow the discovery workflow:

1. `rules/agent-connect-mcp.md` - Connection setup (MCP + CLI), credential discovery, output format selection 2. `rules/agent-discovery-schema.md` - **CRITICAL**: 7-step schema discovery workflow 3. `rules/agent-query-safety.md` - **CRITICAL**: LIMIT, timeouts, progressive exploration

**Every agent session should follow this sequence:**

1. **Connect** — establish connection via MCP or CLI (see `agent-connect-mcp`) 2. **Discover** — databases → tables → columns + comments → sort keys → skip indexes → sample → EXPLAIN 3. **Plan** — use sort key and skip index knowledge to write efficient WHERE clauses 4. **Execute** — run queries with LIMIT and timeouts 5. **Recover** — on timeout/memory errors, narrow filters and retry (see `agent-query-safety`)

Subagent architecture notes

If your system dispatches ClickHouse tasks to specialized subagents:

  • **Schema discovery + query execution**: any model — the steps are procedural
  • **EXPLAIN analysis + query optimization**: benefits from mid-tier reasoning
  • **Schema design review against relevant rules**: benefits from mid-tier reasoning

---

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. `rules/schema-pk-prioritize-filters.md` - Filter column inclusion 4. `rules/schema-types-native-types.md` - Proper type selection 5. `rules/schema-types-minimize-bitwidth.md` - Numeric type sizing 6. `rules/schema-types-lowcardinality.md` - LowCardinality usage 7. `rules/schema-types-avoid-nullable.md` - Nullable vs DEFAULT 8. `rules/schema-partition-low-cardinality.md` - Partition count limits 9. `rules/schema-partition-lifecycle.md` - Partitioning purpose

**Check for:**

  • [ ] PRIMARY KEY / ORDER BY column order (low-to-high cardinality)
  • [ ] Data types match actual data ranges
  • [ ] LowCardinality applied to appropriate string columns
  • [ ] Partition key cardinality bounded (100-1,000 values)
  • [ ] ReplacingMergeTree has version column if used

For Query Reviews (SELECT, JOIN, aggregations)

**Read these rule files:**

1. `rules/query-join-choose-algorithm.md` - Algorithm selection 2. `rules/query-join-filter-before.md` - Pre-join filtering 3. `rules/query-join-use-any.md` - ANY vs regular JOIN 4. `rules/query-index-skipping-indices.md` - Secondary index usage 5. `rules/schema-pk-filter-on-orderby.md` - Filter alignment with ORDER BY

**Check for:**

  • [ ] Filters use ORDER BY prefix columns
  • [ ] JOINs filter tables before joining (not after)
  • [ ] Correct JOIN algorithm for table sizes
  • [ ] Skipping indices for non-ORDER BY filter columns

For Text Search and Native Text-Index Reviews

Read the relevant files directly:

1. `rules/query-index-text-native.md` - Native postings, version baseline, granularity, legacy indexes 2. `rules/query-index-text-semantics.md` - Full search operation map, correctness, phrases, and capability boundaries 3. `rules/query-index-text-analysis.md` - Tokenizers, languages, normalization, stemming, and stop words 4. `rules/query-index-text-plan.md` - Direct read, hints, fallback, and EXPLAIN evidence 5. `rules/query-index-text-lifecycle.md` - Existing-part materialization and migration

For any full-text-search question, establish the search contract (tokens, substrings, phrases, language, fields, ranking), deployed version/build, and indexed expression. Native text indexes store row-ID postings: their large granularity does not restrict them to part-level decisions. Eligible predicates can be exact, candidate hints, or ordinary pruning; preserve the original match semantics.

Read these references for the relevant feature details:

  • [Full feature and analysis guide](references/text-search-feature-guide.md) — supported operations, data shapes, Map/JSON correlation, language tokenizers, parameters, settings, limitations, and operational choices.
  • [Version and evidence ledger](references/text-search-versions.md) — release gates, stable versus development capabilities, and resolved source conflicts.

Do not promise native BM25/fuzzy ranking, universal language segmentation, same-element matches across

Read more
@clickhouse
Ships withclickhouse-best-practices

The official Agent Skills for ClickHouse. These skills help LLMs and agents to adopt best practices when working with ClickHouse and chdb (in-process ClickHouse for Python). You can use these skills with open-source ClickHouse and managed ClickHouse Cloud.

Stars on GitHub

Momentum

stars in total
572
Star history of clickhouse/agent-skills on GitHub, a chart by star-history.com

Other skills on clickhouse-best-practices.

More skills from other plugins.

dbx

dbx

Use the DBX CLI to inspect DBX-managed database connections, explore schemas, run bounded read-only queries, generate DBML or…

dbx5d31k
@t8y2@t8y2Install Skill
docsite-link-sweep

docsite-link-sweep

Sweep the googleapis/mcp-toolbox docs for broken and non-canonical links, report each finding with its cause, and apply the safe…

@googleapis@googleapisInstall Skill
query-builder

query-builder

Convert natural language questions into SQL queries. Activates when users ask data questions in plain English like "show me users…

whodb4d5.1k
@clidey@clideyInstall Skill

Questions about clickhouse-best-practices.

Which coding agents can use clickhouse-best-practices?
clickhouse-best-practices installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.