Optimize Clickhouse Sql logo

Optimize Clickhouse Sql

Community
FrankChen021
optimize-clickhouse-sql

Optimize slow queries, analyze SQL performance, and collect evidence for expensive workloads.

Overview

PublisherFrankChen021
Repositorydatastoria
Skill nameoptimize-clickhouse-sql
Stars
327
Forks
18
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by FrankChen021 on GitHub. Read the source before you install it.

Installation

Install the Optimize Clickhouse Sql AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/FrankChen021/datastoria/tree/master/resources/skills/optimize-clickhouse-sql
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/FrankChen021/datastoria.git /tmp/datastoria
mkdir -p .claude/skills
cp -r /tmp/datastoria/resources/skills/optimize-clickhouse-sql .claude/skills/optimize-clickhouse-sql
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Optimize Clickhouse Sql in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Optimize Clickhouse Sql on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Optimize Clickhouse Sql is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

SQL Optimization Skill

Workflow is evidence-driven: collect evidence with tools, then recommend based on evidence only.

Pre-flight Check

  1. HAS SQL: Conversation contains a SQL query -> Go to WORKFLOW step 2 (Collect Evidence).
  2. HAS QUERY_ID: Conversation contains query_id -> Go to WORKFLOW step 2 (Call collect_sql_optimization_evidence immediately).
  3. DISCOVERY REQUEST: User asks to optimize the slowest/heaviest queries but does not provide SQL/query_id -> Go to WORKFLOW step 1 (Discovery).
  4. NEITHER: Call ask_user_question with exactly one question:
    • header: Please provide one of the following for optimization
    • options:
      • { "id": "sql", "label": "Provide SQL", "input": "text" }
      • { "id": "query_id", "label": "Provide query_id", "input": "text" }
      • { "id": "resource", "label": "Find the query that consumes the most", "input": "select", "choices": ["duration", "cpu", "memory", "disk"] } After the tool returns:
    • If optionId is sql, treat value as the SQL text and continue with evidence collection.
    • If optionId is query_id, treat value as the query_id and continue with evidence collection.
    • If optionId is resource, treat value as the ranking metric and run discovery for the top 1 query in the last 1 day before continuing.

Discovery

  • Prefer search_query_log for discovery from system.query_log (slowest, most expensive, user-scoped, database-scoped, text-scoped, etc.).
  • If search_query_log cannot express the request, then load the clickhouse-system-queries skill, immediately call skill_resource for references/system-query-log.md, and follow that reference strictly.
  • Do NOT write ad-hoc SQL against system.query_log from this skill when search_query_log can satisfy the request.
  • Extract query_id from the discovery results for the next step (evidence collection).

Time Filtering

  • time_window: Relative minutes from now (e.g., 60 = last hour).
  • time_range: Absolute range { from: "ISO date", to: "ISO date" }.
  • When calling collect_sql_optimization_evidence after discovery, you MUST pass the same time_window or time_range used in discovery.

Mode Selection

  • Default collect_sql_optimization_evidence to light mode for the first pass.
  • Prefer omitting the mode argument entirely unless full detail is required.
  • Use mode: "full" only when the user explicitly asks for detailed/raw evidence or the light pass is insufficient.
  • Do not choose full just because the request says "optimize", "analyze", or "investigate".

Workflow

  1. Discovery (if needed): Prefer search_query_log to find candidates. If the request exceeds the tool's schema, then load clickhouse-system-queries, load references/system-query-log.md via skill_resource, and use that reference. Extract query_id from the results.
  2. Collect Evidence: Call collect_sql_optimization_evidence with query_id (preferred) or sql (and same time params if coming from discovery).
  3. Analyze: Review evidence for optimization opportunities.
  4. Recommendations: Rank by Impact/Risk/Effort. Prefer low-risk query rewrites first.
  5. Validate: Use validate_sql for any proposed SQL changes. Add inline comments (-- comment) to highlight key changes.

Table Schema Evidence

  • Use table_schema fields: columns, engine, partition_key, primary_key, sorting_key, secondary_indexes.
  • When optimization_target is present, treat it as the real local-table schema behind a Distributed table and base key/index recommendations on it.
  • Suggest secondary indexes only when evidence shows frequent WHERE filters on selective columns and the index type fits the predicate.
    • Use minmax for range predicates on sorted columns.
    • Use set for low-cardinality equality filters.
    • Use bloom_filter for high-cardinality equality filters (e.g., trace_id, user_id).
    • Use tokenbf_v1 for frequent token-based text search.

Rules

  • Do NOT recommend based on assumptions. If evidence is missing, collect it with tools.
  • If tools return NO meaningful evidence, output only a brief 3-5 sentence message explaining what's missing.
  • Always validate proposed SQL with validate_sql before recommending.
  • If discovery results include both query text and query_id, prefer query_id to avoid truncation issues.
  • If the SQL appears incomplete (truncated/ellipsized/ends mid-clause), use query_id instead of sql.
  • When both query_id and SQL are available, prefer query_id to reduce tokens and avoid truncation issues.

Frequently asked questions

What does the Optimize Clickhouse Sql AI skill do?

Optimize slow queries, analyze SQL performance, and collect evidence for expensive workloads.

Why use Optimize Clickhouse Sql on TypingMind?

Because you install it once and use it with any model. Optimize Clickhouse Sql is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Optimize Clickhouse Sql in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/FrankChen021/datastoria/tree/master/resources/skills/optimize-clickhouse-sql. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Optimize Clickhouse Sql?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Optimize Clickhouse Sql?

As many as you like. As long as a model supports skills, you can use Optimize Clickhouse Sql with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Optimize Clickhouse Sql AI skill free?

It is published on GitHub by FrankChen021. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇