一键导入
n-plus-one-fix
General techniques for identifying and fixing N+1 query problems in ISUCON web applications
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
General techniques for identifying and fixing N+1 query problems in ISUCON web applications
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
MCP tool reference — exec, benchmark_start, benchmark_status, note_write, etc. Use when: executing commands on VMs, running benchmarks, or recording findings
ISUCON13 contest manual — server topology, service management, benchmark execution, and rules. Use when: checking environment setup, running benchmarks, or understanding contest constraints
ISUPipe application manual — features, terms, constraints, and API specs. Use when: understanding the app domain, checking API behavior or MUST/MAY requirements
General strategy for identifying and adding missing database indexes in ISUCON web applications
General techniques for optimizing user icon/avatar image serving in ISUCON web applications
Install and use alp (Access Log Profiler) to identify slow nginx endpoints and analyze request patterns
| name | n-plus-one-fix |
| description | General techniques for identifying and fixing N+1 query problems in ISUCON web applications |
ISUCON の初期実装にはほぼ確実に N+1 クエリ問題が存在する。ループ内でクエリを発行するパターンを見つけて、JOIN やバッチクエリに置き換えるのは定番の最適化。
# ループ内のクエリを探す
grep -n 'for.*{' /path/to/webapp/go/*.go | head -20
# その近くにある SELECT を確認
grep -n 'SELECT\|Query\|QueryRow\|Get\|Find' /path/to/webapp/go/*.go
同じクエリが大量に実行されていれば N+1 の兆候:
pt-query-digest /var/log/mysql/slow.log | head -50
-- Before: SELECT * FROM comments WHERE post_id = ? (ループ内)
-- After:
SELECT c.*, u.name, u.display_name
FROM comments c
INNER JOIN users u ON u.id = c.user_id
WHERE c.post_id = ?
// IDs を集めてまとめて取得
ids := make([]int64, len(items))
for i, item := range items {
ids[i] = item.UserID
}
// SELECT * FROM users WHERE id IN (?, ?, ?, ...)
-- Before: ループで個別 COUNT/SUM
-- After: GROUP BY で一括集計
SELECT user_id, COUNT(*) as cnt, IFNULL(SUM(amount), 0) as total
FROM transactions
GROUP BY user_id