$npx -y skills add saifoelloh/golang-best-practices-skill --skill query-performanceGORM + PostgreSQL query performance review. Use when optimizing slow queries, designing indexes, analyzing N+1 patterns, or configuring connection pools. Trigger on "slow", "optimize", "index", "EXPLAIN", "N+1", or performance degradation.
| 1 | # Query Performance |
| 2 | |
| 3 | Expert-level performance review for GORM + PostgreSQL queries. Detects N+1 patterns, missing indexes, connection pool misconfigurations, and memory-inefficient data fetching. |
| 4 | |
| 5 | ## When to Apply |
| 6 | |
| 7 | Use this skill when: |
| 8 | - An endpoint is slow or degrading under load |
| 9 | - Reviewing repository code for N+1 query patterns |
| 10 | - Designing indexes for new tables or query patterns |
| 11 | - Investigating connection pool exhaustion |
| 12 | - Processing large datasets in background jobs |
| 13 | |
| 14 | ## Rule Categories |
| 15 | |
| 16 | | Priority | Count | Focus | |
| 17 | |---|---|---| |
| 18 | | Critical | 2 | N+1 queries, unindexed foreign keys | |
| 19 | | High | 3 | EXPLAIN ANALYZE, connection pool, batch processing | |
| 20 | | Medium | 2 | COUNT vs len(), partial indexes | |
| 21 | |
| 22 | ## Rules Covered (7 total) |
| 23 | |
| 24 | ### Critical Issues (2) |
| 25 | - `critical-n-plus-one` — Detect and eliminate N+1 query patterns using Preload |
| 26 | - `critical-unindexed-fk` — Index foreign keys and all WHERE clause columns |
| 27 | |
| 28 | ### High-Impact Patterns (3) |
| 29 | - `high-explain-analyze` — Use EXPLAIN (ANALYZE, BUFFERS) before declaring a query optimized |
| 30 | - `high-connection-pool` — Configure connection pool parameters explicitly for production |
| 31 | - `high-find-in-batches` — Use FindInBatches for large dataset processing |
| 32 | |
| 33 | ### Medium Improvements (2) |
| 34 | - `medium-count-query` — Use db.Count instead of len() on full fetch |
| 35 | - `medium-partial-index` — Use partial indexes for filtered queries on large tables |
| 36 | |
| 37 | ## Trigger Phrases |
| 38 | |
| 39 | - "Why is this query slow?" |
| 40 | - "Optimize this query" |
| 41 | - "Check for N+1" |
| 42 | - "Add an index" |
| 43 | - "EXPLAIN output" |
| 44 | - "Performance issue" |
| 45 | - "Connection pool" |
| 46 | - "Process large dataset" |
| 47 | |
| 48 | ## Related Skills |
| 49 | |
| 50 | - [gorm-query-patterns](../gorm-query-patterns/SKILL.md) — For ORM patterns that cause N+1 |
| 51 | - [postgresql-syntax](../postgresql-syntax/SKILL.md) — For ILIKE and index-aware SQL syntax |
| 52 | - [migration-safety](../migration-safety/SKILL.md) — For `CREATE INDEX CONCURRENTLY` in migrations |