sql-optimizer

Analyze SQL queries and EXPLAIN output to recommend indexes and rewrites.

310|45|Updated Feb 22, 2026
One-click install
npx skills add https://github.com/Mathews-Tom/praxis-skills --skill sql-optimizer-mathews-tom
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-optimizer
Source: https://github.com/Mathews-Tom/praxis-skills/tree/main/skills/sql-optimizer
Command: npx skills add https://github.com/Mathews-Tom/praxis-skills --skill sql-optimizer-mathews-tom

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill diagnoses slow SQL queries and EXPLAIN plans to identify index gaps, N+1 patterns, suboptimal joins, and full-table scans, then produces actionable, engine-specific recommendations and safe query rewrites that preserve correctness.

Core Features & Use Cases

  • EXPLAIN interpretation: Translate scan types, join methods, cost hotspots, and estimated vs actual row mismatches into prioritized optimization actions.
  • Anti-pattern detection: Find SELECT *, functions on indexed columns, leading-wildcard LIKE, implicit casts, OR across columns, correlated subqueries (N+1), and missing join conditions.
  • Index and rewrite recommendations: Propose composite, partial, covering, or functional indexes and provide rewritten queries (e.g., converting correlated subqueries to JOINs) with clear explanations of impact and trade-offs.
  • Engine-aware guidance: Tailor suggestions for PostgreSQL, MySQL, and SQLite, and flag when schema changes, denormalization, or materialized views are appropriate.
  • Use cases: Speeding up slow API endpoints, resolving ORM N+1 issues in web apps, and optimizing analytical queries for reporting.

Quick Start

Use the sql-optimizer skill to analyze this SQL query and any provided EXPLAIN output, then return detected issues, recommended indexes, and an optimized query with explanations.

Frequently Asked Questions about sql-optimizer

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

FAQPage Schema
How do I optimize slow SQL queries using EXPLAIN plan output?

SQL query optimization analyzes EXPLAIN plans to identify cost hotspots, full-table scans, and estimated versus actual row mismatches, then recommends engine-specific indexes and rewrites to resolve performance issues.

What is the best way to fix N+1 query problems in ORMs?

Fixing ORM N+1 problems involves detecting correlated subqueries and converting them into efficient JOINs, reducing redundant database calls by rewriting the query structure for better performance.

Does query optimization work for PostgreSQL, MySQL, and SQLite?

Query optimization provides engine-aware guidance tailored for PostgreSQL, MySQL, and SQLite, interpreting specific scan and join types to recommend appropriate composite, partial, or covering indexes.

How do I identify missing indexes causing full-table scans?

Identifying missing indexes requires analyzing EXPLAIN output for full-table scans and high-cost joins, then applying recommendations for composite or functional indexes to target the queried columns.

Can I rewrite a correlated subquery to improve database performance?

Rewriting correlated subqueries into JOINs improves database performance by eliminating row-by-row execution patterns, and optimized queries are provided with clear explanations of impact and trade-offs.

What SQL anti-patterns should I look for to speed up slow API endpoints?

Speeding up slow API endpoints requires detecting SQL anti-patterns like SELECT *, functions on indexed columns, leading-wildcard LIKE, implicit casts, and missing join conditions that degrade query performance.