// Production-grade SQL optimization with AI-assisted query analysis, EXPLAIN ANALYZE automation, balanced indexing strategies, performance tuning, schema design, and operations across PostgreSQL, MySQL, SQL Server, Oracle, SQLite.
| name | data-sql-optimization |
| description | Production-grade SQL optimization with AI-assisted query analysis, EXPLAIN ANALYZE automation, balanced indexing strategies, performance tuning, schema design, and operations across PostgreSQL, MySQL, SQL Server, Oracle, SQLite. |
This skill equips Claude with actionable checklists, patterns, and templates for transactional (OLTP) SQL optimization: AI-powered query analysis, automated EXPLAIN interpretation, intelligent indexing (avoiding over-indexing), performance monitoring with pg_stat_statements, schema evolution, migrations, backup/recovery, high availability, and security.
Supported Platforms: PostgreSQL, MySQL, SQL Server, Oracle, SQLite
For OLAP/Analytics: See data-lake-platform (ClickHouse, DuckDB, Doris, StarRocks)
| Task | Tool/Framework | Command | When to Use |
|---|---|---|---|
| Query Performance Analysis | EXPLAIN ANALYZE | EXPLAIN (ANALYZE, BUFFERS) SELECT ... (PG) / EXPLAIN ANALYZE SELECT ... (MySQL) | Diagnose slow queries, identify missing indexes |
| Find Slow Queries | pg_stat_statements / slow query log | SELECT * FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 10; | Identify performance bottlenecks in production |
| Index Analysis | pg_stat_user_indexes / SHOW INDEX | SELECT * FROM pg_stat_user_indexes WHERE idx_scan = 0; | Find unused indexes, validate index coverage |
| Schema Migration | Flyway / Liquibase | flyway migrate / liquibase update | Version-controlled database changes |
| Backup & Recovery | pg_dump / mysqldump | pg_dump -Fc dbname > backup.dump | Point-in-time recovery, disaster recovery |
| Replication Setup | Streaming / GTID | Configure postgresql.conf / my.cnf | High availability, read scaling |
| Query Optimization | AI-assisted tools | pgai (PostgreSQL) / Performance Schema (MySQL) | ML-based query plan analysis, predictive caching |
Query performance issue?
โโ Identify slow queries first?
โ โโ PostgreSQL โ pg_stat_statements (top queries by total_exec_time)
โ โโ MySQL โ Performance Schema / slow query log
โ
โโ Analyze execution plan?
โ โโ PostgreSQL โ EXPLAIN (ANALYZE, BUFFERS, VERBOSE)
โ โโ MySQL โ EXPLAIN FORMAT=JSON or EXPLAIN ANALYZE
โ โโ SQL Server โ SET STATISTICS IO ON; SET STATISTICS TIME ON;
โ
โโ Need indexing strategy?
โ โโ PostgreSQL โ B-tree (default), GIN (JSONB), GiST (spatial), partial indexes
โ โโ MySQL โ BTREE (default), FULLTEXT (text search), SPATIAL
โ โโ Check: Table >10k rows AND selectivity <10% AND 10x+ speedup verified
โ
โโ Schema changes needed?
โ โโ New database โ template-schema-design.md
โ โโ Modify schema โ template-migration.md (Flyway/Liquibase)
โ โโ Large tables (MySQL) โ gh-ost / pt-online-schema-change (avoid locks)
โ
โโ High availability setup?
โ โโ PostgreSQL โ Streaming replication (template-replication-ha.md)
โ โโ MySQL โ GTID-based replication (template-replication-ha.md)
โ
โโ Backup/disaster recovery?
โ โโ template-backup-restore.md (pg_dump, mysqldump, PITR)
โ
โโ Analytics on large datasets (OLAP)?
โโ See data-lake-platform (ClickHouse, DuckDB, Doris, StarRocks)
Claude should invoke this skill when users ask for:
Find detailed operational patterns and quick references in:
Each file includes:
Templates are organized by database technology for precision and clarity:
Infrastructure & Operations:
Application Integration:
Quality & Security:
Data Engineering & AI:
Resources
Templates
Data
See resources/operational-patterns.md for:
For OLAP databases and data lake infrastructure, see data-lake-platform:
This skill focuses on transactional database optimization (PostgreSQL, MySQL, SQL Server, Oracle, SQLite). Use data-lake-platform for analytical workloads.
This skill focuses on query optimization within a single database. For related workflows:
SQL Transformation & Analytics Engineering: โ ai-ml-data-science skill
Data Ingestion (Loading into Warehouses): โ ai-mlops skill
Data Lake Infrastructure: โ data-lake-platform skill
Use Case Decision:
See data/sources.json for 62+ curated resources including:
Core Documentation:
Modern Optimization (December 2025):
Operations & Infrastructure:
Use resources/operational-patterns.md and the templates directory for detailed workflows, migration notes, and ready-to-run commands.