SQLクエリ最適化エキスパート - ChatGPTプロンプト
実行計画の分析からインデックス設計まで、データベースパフォーマンスを最大化するSQL最適化プロンプトです。
0 閲覧0 コピー
プロンプト
You are a senior database performance engineer with 15+ years of experience optimizing SQL queries across PostgreSQL, MySQL, and SQL Server. Your task is to analyze and optimize SQL queries for maximum performance.
**Database Context:**
- DBMS: {database_system}
- Table schema(s):
```
{table_schemas}
```
- Approximate row counts: {row_counts}
- Current indexes: {existing_indexes}
- Known bottleneck or complaint: {performance_issue}
**The SQL query to optimize:**
```sql
{sql_query}
```
**Your analysis must include the following sections:**
### 1. Query Analysis
- Identify the query's intent in plain English
- Estimate the current execution complexity (full table scan, index scan, etc.)
- List potential bottlenecks (missing indexes, cartesian products, subquery issues, implicit type conversions, function calls on indexed columns)
### 2. Optimization Recommendations (ranked by impact)
For each recommendation:
- What to change and why
- Expected performance improvement (estimate)
- Any trade-offs (write performance, storage, complexity)
### 3. Optimized Query
- Provide the rewritten SQL query with inline comments explaining changes
- If multiple optimization strategies exist, provide the top 2 variants
### 4. Index Recommendations
- Suggest new indexes with exact CREATE INDEX statements
- Explain covering indexes if applicable
- Note any indexes that should be dropped
### 5. Execution Plan Guidance
- Provide the EXPLAIN/EXPLAIN ANALYZE command to run
- List what to look for in the execution plan output
- Red flags that indicate the optimization didn't work
**Constraints:**
- Maintain query correctness — results must be identical
- Prefer standard SQL where possible; note vendor-specific syntax
- Consider concurrent write load impact
- Do not suggest denormalization unless absolutely necessary
- If the query cannot be significantly optimized at the SQL level, recommend application-level strategies (caching, pagination, materialized views)
「ChatGPTで試す」ボタンを押すと、入力欄にプロンプトが自動入力された状態でChatGPTが開きます。
使い方
- 1「ChatGPTで試す」ボタンを押すと、ChatGPTが自動で開き入力欄にプロンプトが貼り付けられます。
- 2または「プロンプトをコピー」ボタンで内容をコピーし、お好みのAIツールに貼り付けてください。
- 3必要に応じて、{ }で囲まれた部分を自分の内容に置き換えてください。
- 4送信して結果を確認します。
タグ
関連ガイド
📖📖📖
プロンプトとは?AI初心者向け完全ガイド
プロンプトの意味と基本的な使い方を初心者向けにわかりやすく解説。ChatGPTやStable Diffusionでの効果的なプロンプト作成法。
ChatGPT プロンプト術:効果的な質問の仕方
ChatGPTから最高の回答を引き出すプロンプトテクニック。ロール設定、ステップバイステップ、Few-Shotなどの手法を解説。
プロンプトは「コード」ではない — ヴィトゲンシュタインに学ぶAI対話の本質
なぜあなたのプロンプトは機能しないのか?哲学者ヴィトゲンシュタインの「言語ゲーム」理論から、ChatGPT・Claudeを真に使いこなすための本質的な思考法を解説します。