sql-optimizer
Skill3 starsChanged 10 months agoMITView on GitHub
Analyzes SQL queries and generates an optimization report notebook with explanations, identified issues, and rewritten queries. Use when the user wants to optimize, explain, improve, or debug a SQL query, or mentions query performance, slow queries, or SQL optimization.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- imtiazrayhan/agentscamp-librarytheir own version, first seen Aug 25, 2026
- Viprasol-Tech/sql-optimizertheir own version, first seen Jun 14, 2026
- JayRHa/AgentSkillstheir own version, first seen Jun 9, 2026
- FutureJJ/claude-skillstheir own version, first seen Mar 7, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- JayRHa/AgentSkills★ 11same name
- FutureJJ/claude-skills★ 3same name
- imtiazrayhan/agentscamp-library★ 1same name
- Viprasol-Tech/sql-optimizer★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository4 other files it gives its agents.
- auto-edaSkill
- dataset-doctorSkill
- experiment-trackerSkill
- paper-to-codeSkill
The file
We split this skill into the rules it gives an agent
5 rules. 0 are common, 3 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
If neither provided, ask the user to paste the query.
- Very specific: line 21
If --dialect is not specified, auto-detect from SQL syntax:
- Distinctive: line 28
If unclear, ask the user.
- Distinctive: line 40
Follow notebook-format.md for structure.
- Very specific: line 155
Create the ./notebooks/ directory if it doesn't exist.
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SQL Optimizer
Input
Parse $ARGUMENTS for:
- Query source — one of:
- Inline SQL query (if the argument looks like SQL).
- Path to a
.sqlfile. - If neither provided, ask the user to paste the query.
--dialectflag — optional. Values:bigquery,postgresql.
Dialect Auto-Detection
If --dialect is not specified, auto-detect from SQL syntax:
- Backtick identifiers (
`project.dataset.table`) → BigQuery ::type casts (e.g.,column::integer) → PostgreSQLSAFE_DIVIDE,STRUCT,UNNEST(ARRAY)→ BigQueryLATERAL JOIN,DISTINCT ON,ILIKE→ PostgreSQLPARTITION BYin DDL context → could be either, default to PostgreSQL- If unclear, ask the user.
Step 1: Analyze the Query
Parse and understand the query:
- Identify all tables, joins, subqueries.
- Trace the execution flow.
- Identify potential performance issues.
- Note the query's intent (what business question it answers).
Step 2: Generate the Notebook
Follow notebook-format.md for structure.
Section 1: Header (markdown)
# SQL Query Analysis
*Generated on {YYYY-MM-DD} by sql-optimizer skill*
*Dialect: {detected_dialect}*Section 2: Original Query (code)
The input query, formatted with proper indentation. Display in a code cell:
query = """
SELECT
c.segment,
COUNT(*) AS order_count,
SUM(o.amount) AS total_spend
FROM orders o
JOIN customers c ON o.customer_id = c.id
WHERE o.order_date >= '2025-01-01'
GROUP BY c.segment
ORDER BY total_spend DESC
"""
print(query)Section 3: Query Explanation (markdown)
Plain-English walkthrough of what the query does:
This query:
1. Joins `orders` with `customers` on `customer_id`.
2. Filters for orders from January 2025 onward.
3. Groups by customer segment.
4. Calculates total order count and spend per segment.
5. Returns segments sorted by highest total spend.Section 4: Execution Flow (markdown)
Step-by-step order of operations as the database engine processes it:
1. **FROM** `orders o` — scan orders table (~N rows estimated)
2. **JOIN** `customers c` ON `o.customer_id = c.id` — hash join
3. **WHERE** `o.order_date >= '2025-01-01'` — filter rows
4. **GROUP BY** `c.segment` — aggregate into groups
5. **SELECT** — compute COUNT(*) and SUM(o.amount)
6. **ORDER BY** `total_spend DESC` — sort results
7. **LIMIT** — (none specified, returns all groups)Note at each stage what the data volume looks like, if inferable.
Section 5: Identified Issues (markdown)
Table with columns: Severity, Issue, Location, Impact.
Critical issues:
- Correlated subqueries (N+1 execution pattern).
SELECT *(unnecessary data transfer, especially in columnar stores).- Full table scans on large tables (missing WHERE on partition column).
- Cartesian joins (missing or incorrect JOIN condition).
Warning issues:
- Implicit type casts (e.g., comparing string to int).
- Functions on indexed columns in WHERE (prevents index usage).
- Missing
LIMITon exploratory queries. - Redundant subqueries that could be CTEs or JOINs.
ORDER BYwithoutLIMIT(sorts entire result set).
Info issues:
- Style improvements (consistent aliasing, indentation).
- Readability suggestions (CTEs vs nested subqueries).
- Aliasing recommendations.
Section 6: Optimized Query (code)
The rewritten query with inline comments explaining each change:
-- Changed: SELECT * → explicit columns (reduces data scanned)
SELECT
c.segment,
COUNT(*) AS order_count,
SUM(o.amount) AS total_spend
-- Changed: implicit join → explicit JOIN (clearer intent)
FROM orders o
INNER JOIN customers c ON o.customer_id = c.id
-- Added: partition filter for BigQuery cost control
WHERE o.order_date >= '2025-01-01'
GROUP BY c.segment
ORDER BY total_spend DESC
-- Added: LIMIT for safety
LIMIT 1000Section 7: Dialect-Specific Tips (markdown)
Based on the detected dialect, reference the appropriate tips file and include the 3-5 most relevant tips for the specific query:
- For BigQuery: see bigquery-tips.md
- For PostgreSQL: see postgresql-tips.md
Select tips that are specifically relevant to patterns found in the analyzed query — not generic advice.
Step 3: Write the Notebook
Write to ./notebooks/sql_optimization_{YYYY-MM-DD}.ipynb.
Create the ./notebooks/ directory if it doesn't exist.
Step 4: Report
Tell the user:
- Where the notebook was saved.
- Number of issues found by severity.
- The single most impactful optimization.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

