// 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.