ワンクリックで
database-query-optimization
When addressing slow application endpoints, high database CPU usage, or standardizing data access patterns.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
When addressing slow application endpoints, high database CPU usage, or standardizing data access patterns.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
When improving read performance and reducing database load.
When designing loosely coupled systems that react to state changes asynchronously.
When setting up telemetry, debugging distributed systems, or standardizing application output.
When creating or extending an HTTP API for client consumption.
When designing how a system recovers from and reports failures.
When asynchronously reviewing peer code before merging into the main branch.
SOC 職業分類に基づく
| name | database-query-optimization |
| description | When addressing slow application endpoints, high database CPU usage, or standardizing data access patterns. |
| version | 2.0.0 |
| category | backend |
| tags | ["backend","database","performance","sql","optimization"] |
| skill_type | workflow |
| author | skiLLM |
| license | MIT |
| compatible_agents | ["claude-code","cursor","copilot","codex"] |
| estimated_context_tokens | 2000 |
| dangerous | true |
| requires_review | true |
| security_level | review-required |
| dependencies | [] |
| triggers | ["slow query","n+1","database performance","sql optimization"] |
| permissions | {"filesystem":{"read":true,"write":true},"network":{"outbound":true},"shell":{"execute":true}} |
| input_requirements | ["slow query","orm code","database schema"] |
| output_contract | ["no select *","no n+1 queries","indexes on where/join columns"] |
| failure_conditions | ["database unavailable","lack of query profiling data","migration cannot be rolled back"] |
| last_updated | "2026-05-15T00:00:00.000Z" |
Slow databases kill applications. This skill replaces guesswork with systematic performance analysis, using EXPLAIN plans and profiling to eliminate N+1 queries, eliminate unnecessary scans, and add targeted indexes so the database bears the computational load, not the application.
filter() in JavaScriptid and name*❌ Anti-pattern (N+1, SELECT , no pagination, missing indexes):
// N+1 problem: 1 query for users + 50 queries for posts
const users = await User.findAll(); // SELECT * (over-fetching)
for (const user of users) {
const posts = await Post.find({ userId: user.id }); // 50 individual queries
console.log(user, posts);
}
// Application-side filtering
const allUsers = await User.find({});
const filtered = allUsers.filter(u => u.status === 'active');
✅ Correct pattern (Join, eager-load, explicit columns, paginated):
// Single optimized query with JOIN and explicit columns
const usersWithPosts = await User.findAll({
attributes: ['id', 'username', 'email'],
include: [{
model: Post,
attributes: ['id', 'title', 'createdAt'],
required: true
}],
limit: 20,
offset: 0,
order: [['createdAt', 'DESC']]
});
// Or raw SQL with pagination
const query = `
SELECT u.id, u.username, p.id, p.title
FROM users u
LEFT JOIN posts p ON u.id = p.user_id
WHERE u.status = $1
ORDER BY u.created_at DESC
LIMIT $2 OFFSET $3
`;
const result = await db.query(query, ['active', 20, 0]);
// Indexes created
// CREATE INDEX idx_posts_user_id ON posts(user_id);
// CREATE INDEX idx_users_status ON users(status) WHERE status = 'active';