home / skills / pluginagentmarketplace / custom-plugin-sql / query-optimization
This skill analyzes SQL queries, suggests indexing and rewriting techniques to boost performance across databases.
npx playbooks add skill pluginagentmarketplace/custom-plugin-sql --skill query-optimizationReview the files below or copy the command above to add this skill to your agents.
---
name: query-optimization
description: SQL query optimization and performance tuning
sasmp_version: "1.3.0"
bonded_agent: 01-sql-fundamentals
bond_type: PRIMARY_BOND
---
# Query Optimization Skill
## Overview
Optimize SQL queries for maximum performance across different database systems.
## Topics Covered
### Query Analysis
- EXPLAIN plans
- Execution statistics
- Cost-based optimization
- Query profiling
- Wait event analysis
### Indexing Strategy
- B-tree indexes
- Covering indexes
- Partial indexes
- Index selection
- Index maintenance
### Query Patterns
- JOIN optimization
- Subquery alternatives
- Aggregate optimization
- Pagination patterns
- Bulk operations
### Database Specific
- PostgreSQL optimization
- MySQL tuning
- SQL Server hints
- Oracle optimization
- Cloud DB optimization
## Prerequisites
- SQL fundamentals
- Database internals basics
## Learning Outcomes
- Analyze query plans
- Create effective indexes
- Rewrite slow queries
- Tune database performance
This skill provides practical SQL query optimization and performance tuning guidance for relational databases. It focuses on analyzing execution plans, selecting and maintaining indexes, and applying query rewrite patterns to reduce latency and resource usage. The content spans common engines including PostgreSQL, MySQL, SQL Server, and Oracle, with cloud-specific considerations.
The skill inspects query execution plans, runtime statistics, and wait events to identify bottlenecks and expensive operations. It recommends index strategies (B-tree, covering, partial), join and aggregation rewrites, and configuration or hint-based adjustments for specific database engines. Actionable steps include profiling queries, validating changes with explain plans, and measuring before/after performance.
Do I need engine-specific knowledge to use this skill?
Basic engine differences are covered, but core techniques like plan analysis and indexing apply across engines. Engine-specific advice is included for deeper tuning.
How do I validate that an optimization is safe?
Validate by comparing EXPLAIN ANALYZE outputs, running tests on staging with representative data, and ensuring query results remain identical before deploying to production.