Query optimize

From AltimateAI/altimate-code · View interactive version

Query optimize is an AI agent skill from the GitHub repository AltimateAI/altimate-code. Analyze and optimize SQL queries for better performance

How to use this skill

Skill file

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:
  1. 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.
  1. Run the verified optimizer:
  1. Run detailed analysis:
  1. Get execution plan (if warehouse connected):
  1. Equivalence verification is built into step 3 (verify_equivalence: true):
  1. 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).
  1. 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:

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).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.