en un clic
optimize-clickhouse-sql
// Optimize slow queries, analyze SQL performance, and collect evidence for expensive workloads.
// Optimize slow queries, analyze SQL performance, and collect evidence for expensive workloads.
Diagnose ClickHouse cluster health and provide concrete remediation.
Diagnose ClickHouse runtime query failures when the user wants database-level cause and fix guidance from an error or numeric error code, not source-code root cause analysis.
Investigate application or repository source code with search_file and read_file to explain behavior, trace root causes of runtime or query errors, and answer with precise file citations.
Query ClickHouse system tables to inspect query logs, monitor cluster health, check replication status, and analyze slow queries. Use when the user mentions "system tables", "query_log", "ClickHouse monitoring", "cluster status", "slow queries", or asks to diagnose ClickHouse operational issues.
Expert system for generating, validating, and optimizing ClickHouse SQL. Use this when the user needs data, queries, or analysis.
Rules for charts and visualization. Use when the user asks for charts, graphs, plots, or visual representations (line, bar, pie, timeseries).
| name | optimize-clickhouse-sql |
| description | Optimize slow queries, analyze SQL performance, and collect evidence for expensive workloads. |
| metadata | {"author":"System","show-in-sql-editor-quick-action":true} |
Workflow is evidence-driven: collect evidence with tools, then recommend based on evidence only.
collect_sql_optimization_evidence immediately).ask_user_question with exactly one question:
header: Please provide one of the following for optimizationoptions:
{ "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:optionId is sql, treat value as the SQL text and continue with evidence collection.optionId is query_id, treat value as the query_id and continue with evidence collection.optionId is resource, treat value as the ranking metric and run discovery for the top 1 query in the last 1 day before continuing.search_query_log for discovery from system.query_log (slowest, most expensive, user-scoped, database-scoped, text-scoped, etc.).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.system.query_log from this skill when search_query_log can satisfy the request.query_id from the discovery results for the next step (evidence collection).time_window: Relative minutes from now (e.g., 60 = last hour).time_range: Absolute range { from: "ISO date", to: "ISO date" }.collect_sql_optimization_evidence after discovery, you MUST pass the same time_window or time_range used in discovery.collect_sql_optimization_evidence to light mode for the first pass.mode argument entirely unless full detail is required.mode: "full" only when the user explicitly asks for detailed/raw evidence or the light pass is insufficient.full just because the request says "optimize", "analyze", or "investigate".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.collect_sql_optimization_evidence with query_id (preferred) or sql (and same time params if coming from discovery).validate_sql for any proposed SQL changes. Add inline comments (-- comment) to highlight key changes.optimization_target is present, treat it as the real local-table schema behind a Distributed table and base key/index recommendations on it.minmax for range predicates on sorted columns.set for low-cardinality equality filters.bloom_filter for high-cardinality equality filters (e.g., trace_id, user_id).tokenbf_v1 for frequent token-based text search.validate_sql before recommending.query_id instead of sql.query_id and SQL are available, prefer query_id to reduce tokens and avoid truncation issues.