Agent SkillsAltimateAI/altimate-code › query-optimize

query-optimize

GitHub

分析SQL查询性能,利用模式检查和执行计划识别反模式,通过等价性验证提供安全优化的重写建议。

.opencode/skills/query-optimize/SKILL.md AltimateAI/altimate-code

Trigger Scenarios

用户请求优化SQL查询性能 需要检查SQL反模式 获取SQL执行计划分析

Install

npx skills add AltimateAI/altimate-code --skill query-optimize -g -y
More Options

Non-standard path

npx skills add https://github.com/AltimateAI/altimate-code/tree/main/.opencode/skills/query-optimize -g -y

Use without installing

npx skills use AltimateAI/altimate-code@query-optimize

指定 Agent (Claude Code)

npx skills add AltimateAI/altimate-code --skill query-optimize -a claude-code -g -y

安装 repo 全部 skill

npx skills add AltimateAI/altimate-code --all -g -y

预览 repo 内 skill

npx skills add AltimateAI/altimate-code --list

SKILL.md

Frontmatter
{
    "name": "query-optimize",
    "description": "Analyze and optimize SQL queries for better performance"
}

Query Optimize

Requirements

Agent: any (read-only analysis) Tools used: altimate_core_rewrite (with verify_equivalence: true), sql_analyze, sql_explain, read, glob, schema_inspect, warehouse_list

Analyze SQL queries for performance issues and suggest concrete optimizations including rewritten SQL.

Workflow

  1. Get the SQL query -- Either:

    • Read SQL from a file path provided by the user
    • Accept SQL directly from the conversation
    • Read from clipboard or stdin if mentioned
  2. Determine the dialect -- Default to snowflake. If the user specifies a dialect (postgres, bigquery, duckdb, etc.), use that instead. Check the project for warehouse connections using warehouse_list if unsure.

  3. Run the verified optimizer:

    • If the user has a warehouse connection, first call schema_inspect on the relevant tables to build schema context (needed both for better rewrites — e.g. SELECT * expansion — and to verify equivalence)
    • Call altimate_core_rewrite with the SQL, schema context, and verify_equivalence: true. This proposes rewrites AND proves each one returns the same results as the original in a single step. The result is partitioned into verified-equivalent rewrites (safe to apply) and unverified rewrites (review before applying), so you never recommend a rewrite that silently changes semantics.
  4. Run detailed analysis:

    • Call sql_analyze with the same SQL and dialect to get the full anti-pattern breakdown with recommendations
  5. Get execution plan (if warehouse connected):

    • Call sql_explain to run EXPLAIN on the query and get the execution plan
    • Look for: full table scans, sort operations on large datasets, inefficient join strategies, missing partition pruning
    • Include key findings in the report under "Execution Plan Insights"
  6. Equivalence verification is built into step 3 (verify_equivalence: true):

    • Present the verified-equivalent rewrites as safe to apply.
    • Present unverified rewrites separately with their reason ("review before applying") — do not recommend applying these without manual review.
    • If no schema was available, all rewrites come back unverified; say so and recommend supplying a schema (or a warehouse connection) to enable verification.
  7. Present findings in a structured format:

Query Optimization Report
=========================

Summary: X suggestions found, Y anti-patterns detected

High Impact:
  1. [REWRITE] Replace SELECT * with explicit columns
     Before: SELECT *
     After:  SELECT id, name, email

  2. [REWRITE] Use UNION ALL instead of UNION
     Before: ... UNION ...
     After:  ... UNION ALL ...

Medium Impact:
  3. [PERFORMANCE] Add LIMIT to ORDER BY
     ...

Optimized SQL:
--------------
SELECT id, name, email
FROM users
WHERE status = 'active'
ORDER BY name
LIMIT 100

Anti-Pattern Details:
---------------------
  [WARNING] SELECT_STAR: Query uses SELECT * ...
    -> Consider selecting only the columns you need.
  1. If schema context is available, mention that the optimization used real table schemas for more accurate suggestions (e.g., expanding SELECT * to actual columns).

  2. If no issues are found, confirm the query looks well-optimized and briefly explain why (no anti-patterns, proper use of limits, explicit columns, etc.).

Usage

The user invokes this skill with SQL or a file path:

  • /query-optimize SELECT * FROM users ORDER BY name -- Optimize inline SQL
  • /query-optimize models/staging/stg_orders.sql -- Optimize SQL from a file
  • /query-optimize -- Optimize the most recently discussed SQL in the conversation

Use the tools: altimate_core_rewrite with verify_equivalence: true (proposes rewrites AND proves they preserve results in one step), sql_analyze, sql_explain (execution plans), read (for file-based SQL), glob (to find SQL files), schema_inspect (for schema context), warehouse_list (to check connections).

Version History

  • 8c9a9a8 Current 2026-07-25 06:35

Same Skill Collection

.opencode/skills/altimate-setup/SKILL.md
.opencode/skills/cost-report/SKILL.md
.opencode/skills/data-parity/SKILL.md
.opencode/skills/dbt-analyze/SKILL.md
.opencode/skills/dbt-docs/SKILL.md
.opencode/skills/dbt-pr-review/SKILL.md
.opencode/skills/dbt-test/SKILL.md
.opencode/skills/dbt-troubleshoot/SKILL.md
.opencode/skills/dbt-unit-tests/SKILL.md
.opencode/skills/lineage-diff/SKILL.md
.opencode/skills/pii-audit/SKILL.md
.opencode/skills/schema-migration/SKILL.md
.opencode/skills/sql-review/SKILL.md
.opencode/skills/sql-translate/SKILL.md
.opencode/skills/teach/SKILL.md
.opencode/skills/train/SKILL.md
.opencode/skills/training-status/SKILL.md
.opencode/skills/data-viz/SKILL.md
.opencode/skills/dbt-develop/SKILL.md
.opencode/skills/dbt-schema-verify/SKILL.md

Metadata

Files
0
Version
e27aeac
Hash
643cd0ec
Indexed
2026-07-25 06:35

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-20 05:28
浙ICP备14020137号-1 $mapa de visitantes$