sql-optimization

Analyzes and rewrites slow SQL queries with indexing and performance tuning guidance.

Updated Jul 21, 2026
One-click install
npx skills add https://github.com/afonsoft/gamehub --skill sql-optimization-afonsoft
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sql-optimization
Source: https://github.com/afonsoft/gamehub/tree/main/.claude/skills/sql-optimization
Command: npx skills add https://github.com/afonsoft/gamehub --skill sql-optimization-afonsoft

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Slow SQL queries and database performance bottlenecks degrade application responsiveness, and diagnosing them requires deep knowledge of indexing, join strategies, and query execution plans across different database engines. ## Core Features & Use Cases - Query Rewriting: Converts anti-patterns like SELECT *, correlated subqueries, and function-wrapped WHERE clauses into index-friendly equivalents. - Index Strategy Design: Recommends composite, covering, and partial indexes matched to actual query patterns. - Cross-Database Tuning: Provides optimization techniques for MySQL, PostgreSQL, SQL Server, and Oracle, including slow-query identification queries for each engine. - Use Case: A developer notices a paginated product listing takes seconds to load at high offsets; the Skill rewrites the OFFSET-based pagination into cursor-based pagination and suggests the supporting index. ## Quick Start Ask the assistant to analyze and optimize a slow SQL query or review the database queries in the selected code for performance bottlenecks.

Frequently Asked Questions about sql-optimization

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

FAQPage Schema
How do I optimize a slow SQL query?▼

Start by identifying the bottleneck with your database's slow query log or execution plan tools, then rewrite anti-patterns like SELECT *, functions in WHERE clauses, and correlated subqueries. Add indexes on filtered and joined columns to support the rewritten query.

How to speed up pagination with large OFFSET in SQL?▼

Replace OFFSET-based pagination with cursor-based pagination using a WHERE clause on an indexed column such as created_at or id. This avoids scanning and discarding thousands of rows, keeping response time constant regardless of page depth.

Does this optimization guidance work for PostgreSQL and MySQL?▼

Yes, the techniques are database-agnostic and cover MySQL, PostgreSQL, SQL Server, and Oracle. It includes engine-specific monitoring queries such as pg_stat_statements for PostgreSQL and the MySQL slow log.

Why is my SQL query slow even with an index?▼

Indexes are bypassed when WHERE clauses wrap columns in functions like UPPER() or YEAR(), when composite index column order does not match the query, or when OR conditions prevent index usage. Rewriting predicates to be sargable restores index usage.

When should I use a covering index versus a partial index?▼

Use a covering index when a query repeatedly selects the same columns so the engine can answer entirely from the index. Use a partial index when queries consistently filter on a specific condition, such as active order statuses, to keep the index small.