sql-optimization skill
インデックス戦略、クエリ分析、スキーマ設計、および実装パターンを通じてデータベースのパフォーマンスを最適化します。
- GitHubスター
- 23
- ファイル
- 1
- 最終コミット
- 2026年11月11日
- ライセンス
- CC-BY-SA-4.0
- 許可されたツール
- —
sql-optimization skillは何をしますか
インデックス戦略、クエリ分析、スキーマ設計、および実装パターンを通じてデータベースのパフォーマンスを最適化します。
skillのSKILL.mdから生成された要約。
sql-optimization skill について
クエリチューニングとスキーマ設計を通じてデータベースのパフォーマンスを向上させることが、このSKILLの主な機能です。開発者は、低速なクエリの分析、効率的なインデックス戦略の設計、またはより優れたデータパターンの実装が必要な際にこれを利用します。エージェントはこのSKILLをロードすることで、複合インデックスの適用、N+1問題の回避、低速なoffset limitの代わりにカーソルベースのページネーションを利用するといった原則を適用し、非効率なSQLを高性能なコードへと変換できます。
このSKILLは、EXPLAIN ANALYZEの出力結果の解釈や、シーケンシャルスキャンとインデックスオンリースキャンの区別に関する具体的なガイダンスを提供します。また、書き込み負荷の高いワークロード向けの正規化や、読み取り速度向上のための非正規化など、スキーマ最適化のテクニックもカバーしています。セキュリティを維持するため、SQLインジェクションを防ぐためのパラメータ化されたステートメントの使用を強調し、本番データベースではなく、サニタイズされたステージング環境でパフォーマンスベンチマークを実行することを推奨します。さらに、複雑なクエリによるリソース枯渇を防ぐためのステートメントタイムアウトの使用も提案しています。
エージェントができること
- 1低速なクエリ実行計画の分析EXPLAIN ANALYZEの出力結果を調査し、クエリが低速なフルテーブルスキャンを実行しているかどうかを特定します。
skill の SKILL.md から作成されています。すべてのユースケースは、その引用と照合されています。
sql-optimization skillのインストール方法
各コマンドはskillフォルダをクライアントのskillsディレクトリにコピーします。読み込むには、クライアントを再起動するか新しいセッションを開始してください。プラグインにsql-optimization skillをインストールする
/plugin marketplace add andreibesleaga/GABBE /plugin install gabbe-data@gabbe
Claude Codeにsql-optimization skillをインストールする
~/.claude/skills/sql-optimization/SKILL.md
$ npx degit andreibesleaga/GABBE/plugins/gabbe-data/skills/sql-optimization ~/.claude/skills/sql-optimizationClaude Code (project)にsql-optimization skillをインストールする
.claude/skills/sql-optimization/SKILL.md
$ npx degit andreibesleaga/GABBE/plugins/gabbe-data/skills/sql-optimization .claude/skills/sql-optimizationCodexにsql-optimization skillをインストールする
~/.agents/skills/sql-optimization/SKILL.md
$ npx degit andreibesleaga/GABBE/plugins/gabbe-data/skills/sql-optimization ~/.agents/skills/sql-optimizationGemini CLIにsql-optimization skillをインストールする
~/.gemini/skills/sql-optimization/SKILL.md
$ npx degit andreibesleaga/GABBE/plugins/gabbe-data/skills/sql-optimization ~/.gemini/skills/sql-optimizationClaude.aiにsql-optimization skillをインストールする
npx degit andreibesleaga/GABBE/plugins/gabbe-data/skills/sql-optimization sql-optimization && zip -r sql-optimization.zip sql-optimization # claude.ai → Customize → Skills → + → Create skill → Upload a skill → sql-optimization.zip
自動チェック
実行日 2026年11月16日完全なレポート →まだ検証されていません。スキルにはスコア 80、重大な指摘なし、チェックに十分なデータが必要です。 チェックの仕組み · 点数を上げるための改善点
- ソースリポジトリがリンクされており、アクセス可能andreibesleaga/gabbe/plugins/gabbe-data/skills/sql-optimization is public and reachablegithub.com/andreibesleaga/gabbe/tree/HEAD/plugins/gabbe-data ↗合格
- オープンソースライセンス (OSI)CC-BY-SA-4.0 is not OSI-approvedspdx.org/licenses/CC-BY-SA-4.0.html ↗検出事項
- 過去1年以内にコミットまたはリリースありLast commit 2026-11-11github.com/andreibesleaga/gabbe/commits ↗合格
- スクリプトにダウンロード実行や認証情報の窃取がないNo scripts in the skill folder合格
- SKILL.md に隠れた指示がないNo override phrases, safeguard switches, credential requests or hidden charactersgithub.com/andreibesleaga/gabbe/blob/HEAD/plugins/gabbe-data ↗合格
- 事前許可ツールが限定されているNo pre-approved tools; the agent asks before using onegithub.com/andreibesleaga/gabbe/blob/HEAD/plugins/gabbe-data ↗合格
- SKILL.md が Agent Skills の形式に従っているValid name and description; says when to use it; 81 linesgithub.com/andreibesleaga/gabbe/blob/HEAD/plugins/gabbe-data ↗合格
SKILL.md
GitHubで表示sql-optimization Skill
Goal
This skill focuses on ensuring database interactions are performant and scalable.
Steps
1. The Golden Rule: Indexing
- Primary Keys: Always indexed by default (B-Tree).
- Foreign Keys: MUST be indexed manually in most DBs (Postgres/MySQL) to avoid full table scans on joins.
- Where Clauses: Columns used in
WHERE,ORDER BY,GROUP BYneed indexes. - Composite Indexes: Order matters!
(last_name, first_name)supports lookup bylast_nameORlast_name + first_name, but NOT byfirst_namealone.
2. Analyzing Queries (EXPLAIN ANALYZE)
Always run EXPLAIN ANALYZE on suspect queries.
| Output Term | Meaning | Action |
|---|---|---|
| Seq Scan / Full Table Scan | Reading every row. | Bad (unless table is tiny). Add an index. |
| Index Scan | Reading index + looking up heap. | Good. |
| Index Only Scan | Reading only index. | Best. (Covering Index). |
| Nested Loop | Looping for joins. | Fine for small datasets. Bad for large. |
| Hash Join | Building hash table for join. | Good for large datasets. |
3. Implementation Patterns
1. Select Only What You Need
- Bad:
SELECT * FROM users - Good:
SELECT id, name FROM users - Reason: Reduces IO, network payload, and memory usage.
2. Solve the N+1 Problem
- Problem: Fetching 100 posts, then running 100 queries to get authors.
- Fix: Use
JOINor eager loading (ORM specific:include,with). - Detection: Use logs or APM query counts.
3. Pagination
- Offset/Limit:
OFFSET 1000000is slow (DB scans 1M rows then discards). - Cursor/Keyset:
WHERE id > last_seen_id LIMIT 10. O(1) performance.
4. Transactions
- Keep them short.
- Don't make external API calls inside a DB transaction (holds locks).
4. Schema Optimization
- Normalization (3NF): Reduces redundancy, ensures integrity. Good for write-heavy.
- Denormalization: Adds redundancy for read speed (e.g., storing
author_nameonpoststable). - Data Types: Use the smallest needed type.
VARCHAR(255)vsTEXT(Postgres treats similar, MySQL differs).INTvsBIGINT.JSONB(Postgres) for unstructured data, but don't overuse it.
5. Maintenance
- Run
VACUUM ANALYZE(Postgres) regularly to update planner statistics. - Monitor index usage. Remove unused indexes (they slow down writes).
Security & Guardrails
1. Skill Security (SQL Optimization)
- Query Parameterization: Optimized queries must always use parameterized statements or prepared statements to prevent SQL Injection (SQLi). Never concatenate strings for query building.
- Safe EXPLAIN Execution: Be cautious when running
EXPLAIN ANALYZE, as it actually executes the query. On production, ensure it is only run onSELECTstatements, as running it onINSERT/UPDATE/DELETEwill modify data.
2. System Integration Security
- Resource Exhaustion Prevention: Limit the execution time of optimized queries (e.g.,
statement_timeoutin Postgres) to prevent Denial of Service (DoS) attacks via complex, CPU-intensive queries. - Data Exposure Restrictions: When optimizing
SELECTqueries or adding denormalized columns, ensure that access control rules (Row-Level Security) are maintained and sensitive columns are not inadvertently exposed.
3. LLM & Agent Guardrails
- SQLi Generation Defense: LLMs tasked with optimizing SQL must be strictly instructed and verified to output parameterized queries, rejecting user inputs that attempt to inject raw SQL commands.
- Execution Sandboxing: Agents must not execute optimized queries directly against production databases. Performance benchmarking must be done in a sanitized, ephemeral staging environment.
- Data Masking in Context: When feeding slow queries and
EXPLAINplans into an LLM for analysis, all literal values (e.g., specific user emails, IDs) must be masked or redacted to prevent PII leakage into the model's context.
このスキルのファイル
1sql-optimization skillに関する質問
Claude Codeにsql-optimization skillをインストールするには
npx degit andreibesleaga/GABBE/plugins/gabbe-data/skills/sql-optimization ~/.claude/skills/sql-optimizationを実行してください。Claude Codeは~/.claude/skills(すべてのプロジェクト)または.claude/skills(単一プロジェクト)からskillsを読み込み、説明がタスクに一致する場合にskillを使用します。
sql-optimization skillはどのクライアントで使用できますか
Agent Skills形式を読み込むすべてのクライアントで使用できます: Claude Code、Codex、Gemini CLI、claude.ai(ZIPとしてアップロード)。skill内のスクリプトは、クライアントがコード実行を許可した場合にのみ実行されます。
EXPLAIN ANALYZEを使用して低速なクエリを特定するにはどうすればよいですか?
出力結果に 'Seq Scan' や 'Full Table Scan' が含まれているかを確認してください。これらはデータベースがすべての行を読み取っていることを示しており、インデックスが必要な可能性があります。