optimizing-sql-queries skill
Optimize slow analytical SQL by reading query/EXPLAIN plans, cutting scanned data, fixing join strategy, and using partitioning, clustering, and indexes across Postgres, Snowflake, BigQuery, Databricks/Spark SQL, and Redshift. Use when a query is slow, times out, costs too much, scans too many rows/bytes, or spills to disk.
- GitHubスター
- 27
- ファイル
- 2
- 最終コミット
- 2026年8月30日
- ライセンス
- —
- 許可されたツール
- —
optimizing-sql-queries skillは何をしますか
optimizing-sql-queriesはAgent Skillsです。 Optimize slow analytical SQL by reading query/EXPLAIN plans, cutting scanned data, fixing join strategy, and using partitioning, clustering, and indexes across Postgres, Snowflake, BigQuery, Databricks/Spark SQL, and Redshift. Use when a query is slow, times out, costs too much, scans too many rows/bytes, or spills to disk.
optimizing-sql-queries skillのインストール方法
各コマンドはskillフォルダをクライアントのskillsディレクトリにコピーします。読み込むには、クライアントを再起動するか新しいセッションを開始してください。プラグインにoptimizing-sql-queries skillをインストールする
/plugin marketplace add Unknown-333/awesome-data-engineering-skills /plugin install data-engineering-skills@awesome-data-engineering-skills
Claude Codeにoptimizing-sql-queries skillをインストールする
~/.claude/skills/optimizing-sql-queries/SKILL.md
$ npx degit Unknown-333/awesome-data-engineering-skills/skills/optimizing-sql-queries ~/.claude/skills/optimizing-sql-queriesClaude Code (project)にoptimizing-sql-queries skillをインストールする
.claude/skills/optimizing-sql-queries/SKILL.md
$ npx degit Unknown-333/awesome-data-engineering-skills/skills/optimizing-sql-queries .claude/skills/optimizing-sql-queriesCodexにoptimizing-sql-queries skillをインストールする
~/.agents/skills/optimizing-sql-queries/SKILL.md
$ npx degit Unknown-333/awesome-data-engineering-skills/skills/optimizing-sql-queries ~/.agents/skills/optimizing-sql-queriesGemini CLIにoptimizing-sql-queries skillをインストールする
~/.gemini/skills/optimizing-sql-queries/SKILL.md
$ npx degit Unknown-333/awesome-data-engineering-skills/skills/optimizing-sql-queries ~/.gemini/skills/optimizing-sql-queriesClaude.aiにoptimizing-sql-queries skillをインストールする
npx degit Unknown-333/awesome-data-engineering-skills/skills/optimizing-sql-queries optimizing-sql-queries && zip -r optimizing-sql-queries.zip optimizing-sql-queries # claude.ai → Customize → Skills → + → Create skill → Upload a skill → optimizing-sql-queries.zip
SKILL.md
GitHubで表示Optimizing SQL Queries
When to use
- A query is slow, times out, or is expensive (bytes/credits/slots scanned).
- A dashboard or model run regressed after data grew.
- You see full-table scans, large shuffles, disk spills, or exploding row counts.
- Do NOT use for query correctness bugs — this skill assumes results are correct.
Workflow
- [ ] Read the actual query/EXPLAIN plan (not guesses)
- [ ] Find the dominant cost: scan, join, aggregation, or sort/spill
- [ ] Reduce data read (predicates, partition/cluster pruning, column pruning)
- [ ] Fix join strategy (order, keys, broadcast vs shuffle, skew)
- [ ] Re-measure and confirm the plan changed
- Get the plan. Never optimize blind:
- Postgres:
EXPLAIN (ANALYZE, BUFFERS) <query> - Snowflake: Query Profile UI, or
SYSTEM$EXPLAIN_PLAN_JSON - BigQuery: execution details /
--dry_runfor bytes billed - Spark/Databricks:
df.explain("formatted")or the SQL plan tab
- Postgres:
- Identify the dominant operator by time/rows/bytes. Optimize that first; ignore cheap nodes.
- Reduce data scanned before anything else — it usually dominates cost.
- Fix the join only after the scan is minimal.
- Re-run the plan and verify the change (row estimates, join type, pruning).
Patterns
Enable partition/cluster pruning — push filters on the partition/cluster key so the engine skips files. On BigQuery/Snowflake this is the single biggest lever.
-- Good: filter on the partitioning column with a literal/range so pruning applies
SELECT user_id, SUM(amount)
FROM orders
WHERE order_date >= '2026-01-01' AND order_date < '2026-02-01' -- prunes partitions
GROUP BY user_id;
Filter before joining, not after. Reduce each side to the needed rows/columns first so the join processes less data.
Prefer explicit column lists over SELECT * in columnar warehouses — reading
fewer columns reads fewer bytes.
Choose the right join for the sizes. A small dimension joined to a large fact
should broadcast (map-side) rather than shuffle. In Spark, let Adaptive Query
Execution pick, or hint /*+ BROADCAST(dim) */.
Aggregate/pre-filter in a CTE to shrink data before an expensive window or join, rather than computing over the full table.
Common pitfalls
- Wrapping the partition key in a function (
WHERE DATE(ts) = ...) disables pruning — filter on a raw range instead. - Implicit type casts on join keys (string vs int) force full scans and block index/pruning use — align types.
SELECT DISTINCTto hide a fan-out join — fix the join grain instead; it is cheaper and correct.ORacross columns often prevents index/pruning use — rewrite asUNION ALLorIN.- Optimizing a cheap node — always target the dominant operator in the plan.
- Chasing indexes on columnar warehouses — Snowflake/BigQuery have no row-store indexes; use clustering/partitioning and result caching instead.
References
このスキルのファイル
2optimizing-sql-queries skillに関する質問
Claude Codeにoptimizing-sql-queries skillをインストールするには
npx degit Unknown-333/awesome-data-engineering-skills/skills/optimizing-sql-queries ~/.claude/skills/optimizing-sql-queriesを実行してください。Claude Codeは~/.claude/skills(すべてのプロジェクト)または.claude/skills(単一プロジェクト)からskillsを読み込み、説明がタスクに一致する場合にskillを使用します。
optimizing-sql-queries skillはどのクライアントで使用できますか
Agent Skills形式を読み込むすべてのクライアントで使用できます: Claude Code、Codex、Gemini CLI、claude.ai(ZIPとしてアップロード)。skill内のスクリプトは、クライアントがコード実行を許可した場合にのみ実行されます。