Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Execute use when you need to work with query optimization. This skill provides query performance analysis with comprehensive guidance and automation. Trigger with phrases like "optimize queries", "analyze performance", or "improve query speed".
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-10 | ✗→✓ | ▲ Improved | 31% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 155% | 0% |
| case-08 | ✓→✓ | = Same ✓ | 229% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 119% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 34% | 0% |
Analyze slow database queries using execution plans, wait statistics, and I/O metrics across PostgreSQL, MySQL, and MongoDB. This skill captures EXPLAIN output, identifies sequential scans on large tables, detects missing indexes, measures buffer cache hit ratios, and produces actionable optimization recommendations ranked by expected performance impact.
EXPLAIN ANALYZE (PostgreSQL), EXPLAIN FORMAT=JSON (MySQL), or explain() (MongoDB)pg_stat_statements extension enabled for PostgreSQL (provides aggregated query statistics)psql, mysql, or mongosh CLI tools installedpg_stat_statements (PostgreSQL): SELECT query, calls, mean_exec_time, total_exec_time FROM pg_stat_statements ORDER BY mean_exec_time DESC LIMIT 20. For MySQL, enable and query the slow query log or performance_schema.events_statements_summary_by_digest.EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) on each slow query in PostgreSQL, or EXPLAIN ANALYZE FORMAT=JSON in MySQL. Capture the full execution plan including actual row counts, loop iterations, and buffer usage.rows_removed_by_filter relative to rows (predicate not selective enough)SELECT heap_blks_read, heap_blks_hit, heap_blks_hit::float / (heap_blks_hit + heap_blks_read) AS cache_hit_ratio FROM pg_statio_user_tables WHERE relname = 'table_name'. A ratio below 0.95 suggests the working set exceeds available shared_buffers.SELECT indexrelname, idx_scan, idx_tup_read, idx_tup_fetch FROM pg_stat_user_indexes WHERE schemaname = 'public' ORDER BY idx_scan ASC. Indexes with zero scans are unused and waste write performance.SELECT relname, n_live_tup, n_dead_tup, n_dead_tup::float / GREATEST(n_live_tup, 1) AS dead_ratio FROM pg_stat_user_tables WHERE n_dead_tup > 1000 ORDER BY dead_ratio DESC. A dead tuple ratio above 0.2 indicates the table needs VACUUM.| Error | Cause | Solution | |-------|-------|---------| | EXPLAIN ANALYZE takes too long on production | Query modifies data or runs for minutes | Use EXPLAIN without ANALYZE for estimated plans; run EXPLAIN ANALYZE on staging with representative data | | pg_stat_statements not available | Extension not installed or not in shared_preload_libraries | Run CREATE EXTENSION pg_stat_statements; add to shared_preload_libraries in postgresql.conf and restart | | Execution plan differs between staging and production | Different data distribution, statistics, or configuration | Run ANALYZE on staging tables to update statistics; match work_mem, random_page_cost, and effective_cache_size settings | | Index recommendation causes slow writes | Too many indexes on a write-heavy table | Limit indexes to 5-7 per table; use partial indexes to reduce scope; consider covering indexes to replace multiple single-column indexes | | Query plan uses wrong index | Stale statistics or cost model miscalculation | Run ANALYZE table_name to refresh statistics; adjust random_page_cost for SSD storage; use SET enable_seqscan = off to test index plans |
Optimizing a dashboard aggregate query: A query computing daily revenue with GROUP BY date and JOIN across orders and line_items takes 12 seconds. EXPLAIN reveals a sequential scan on line_items (5M rows). Adding a composite index on (order_id, created_at) with INCLUDE (amount) reduces execution to 200ms by enabling an index-only scan.
Diagnosing N+1 query pattern: Application loads a list page showing 50 products, each with a separate query for category name. pg_stat_statements reveals SELECT name FROM categories WHERE id = $1 called 50 times per page load. Resolution: rewrite as a single JOIN query or implement eager loading in the ORM.
Identifying bloated table causing cache misses: Buffer cache hit ratio drops to 0.78 on the sessions table. Investigation reveals 80% dead tuples due to aggressive INSERT/DELETE cycling without autovacuum tuning. Setting autovacuum_vacuum_scale_factor = 0.01 and running VACUUM FULL restores cache hit ratio to 0.99.
Other measured skills in the registry, with their headline benchmark lift.