query-optimization-agent

Analyze SQL queries and produce rewritten SQL, index recommendations, and execution plan comparisons.

Updated Dec 3, 2025
One-click install
npx skills add https://github.com/Unicorn/Radium --skill query-optimization-agent
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: query-optimization-agent
Source: https://github.com/Unicorn/Radium/tree/main/skills/data/query-optimization-agent
Command: npx skills add https://github.com/Unicorn/Radium --skill query-optimization-agent

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill identifies performance bottlenecks in slow or inefficient SQL queries and provides actionable optimizations to reduce latency and resource usage.

Core Features & Use Cases

  • Execution Plan Analysis: Interpret EXPLAIN output to find full table scans, bad join orders, and costly operations.
  • Index Recommendations: Suggest appropriate indexes and evaluate trade-offs for write overhead and maintenance.
  • Query Rewrites & Anti-pattern Fixes: Rewrite JOINs, subqueries, and CTEs to improve execution, and resolve N+1 query patterns in application code.
  • Use Case: When a web application experiences slow page loads due to heavy DB access, provide rewritten SQL, index DDL, and expected performance gains to guide implementation.

Quick Start

Provide the slow SQL query, the table schemas, current indexes, and the EXPLAIN plan and ask for optimized SQL, index suggestions, and an execution plan comparison.

Frequently Asked Questions about query-optimization-agent

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize slow SQL queries using an execution plan?

To optimize slow SQL queries, analyze the EXPLAIN execution plan to identify full table scans and bad join orders. Apply index recommendations and rewrite JOINs or subqueries to reduce latency and resource usage.

What is the best way to fix N+1 query patterns in application code?

Fixing N+1 query patterns involves rewriting application code to batch related database queries or use JOINs. This eliminates repeated single-row lookups, significantly reducing database access latency and improving page load speeds.

How do you analyze an EXPLAIN plan to find performance bottlenecks?

Analyzing an EXPLAIN plan reveals performance bottlenecks by highlighting costly operations like full table scans and inefficient join orders. Interpreting this output guides targeted SQL rewrites and index creation.

Do I need to provide table schemas and indexes for SQL query tuning?

Yes, providing table schemas, current indexes, and slow query logs is required for SQL query tuning. This context enables accurate index recommendations, execution plan comparisons, and performance improvement estimates.

What are the trade-offs of adding database indexes for query optimization?

Database indexes improve read performance for query optimization but introduce trade-offs for write overhead and maintenance. Evaluate these trade-offs to balance faster SELECT operations against slower INSERT, UPDATE, and DELETE execution.

Why does my SQL query do a full table scan instead of using indexes?

A SQL query performs a full table scan instead of using indexes due to missing or inappropriate indexes, or bad join orders. Analyzing the EXPLAIN plan identifies these costly operations to recommend appropriate index DDL.