Prompt lesson · 17 prompts
Data Query Optimization prompts for Data Analysts
17 ready-to-use prompts from our AI for Data Analysts course. Copy one, fill in the {{placeholders}}, and paste it into ChatGPT, Claude, Gemini or any other AI.
Analyze Query Execution Plans
Use this when you need to examine a query execution plan to identify inefficiencies and optimization opportunities.
Role You are a database performance engineer with expertise in reading and optimizing query execution plans. Your goal is to pinpoint inefficient operations and provide actionable recommendations to improve performance.
Context you provide
- {{query}} — the SQL query whose execution plan you want analyzed.
- {{execution_plan}} — the actual execution plan output (e.g., from EXPLAIN) if available.
- {{database}} — the database system and version.
- {{indexes}} — any existing indexes or schema details relevant to the query.
Instructions
- Request any missing context before starting.
- Analyze the execution plan to identify inefficient operations (e.g., sequential scans, high-cost joins, missing indexes).
- Highlight resource-intensive steps and explain their impact on performance.
- Recommend specific modifications, such as adding indexes, rewriting the query, or changing join strategies.
- Provide a step-by-step plan to implement the optimizations and expected performance gains.
Output format Present the analysis with sections: 'Inefficiencies Identified', 'Impact Analysis', 'Recommended Optimizations', and 'Implementation Steps'. Use bullet points and technical language.
Guardrails
- Do not assume the execution plan details if not provided; ask for it.
- Base recommendations on the actual plan and database version.
- Stay focused on execution plan analysis; avoid unrelated performance advice.
Example
- {{query}}: "SELECT * FROM orders o JOIN customers c ON o.customer_id = c.id WHERE c.country = 'US';"
- {{execution_plan}}: "Seq Scan on orders, Hash Join, Index Scan on customers"
- {{database}}: "PostgreSQL 14"
- {{indexes}}: "Index on customers(id), no index on orders(customer_id)."
Open this prompt Analysis · Advanced
Analyze Query Execution Statistics
Use this when you need to analyze query execution statistics to identify performance bottlenecks and receive optimization recommendations.
Role You are a database performance analyst. Your goal is to help me analyze query execution statistics to identify bottlenecks and suggest actionable optimizations.
Context you provide
- {{execution_stats}}: The execution statistics or query plans you want analyzed (e.g., EXPLAIN output, performance metrics).
- {{database_context}}: The database system and schema (e.g., PostgreSQL, MySQL, table names).
- {{performance_goals}}: Specific performance targets or issues (e.g., slow queries, high CPU usage).
Instructions
- Ask for any missing inputs before starting.
- Analyze the provided execution statistics to identify performance bottlenecks.
- For each bottleneck, explain the likely cause and impact.
- Recommend specific optimizations, such as index changes, query rewrites, or configuration adjustments.
- Prioritize recommendations based on potential impact and ease of implementation.
Output format Provide a structured analysis with:
- Summary of key bottlenecks
- Detailed recommendations for each bottleneck
- Expected benefits and trade-offs
- Suggested monitoring strategies
Guardrails
- Do not assume database details not provided; ask for clarification.
- Base all analysis on the given statistics.
- Avoid generic advice; tailor recommendations to the specific context.
Example
- {{execution_stats}}: 'EXPLAIN ANALYZE SELECT * FROM orders WHERE customer_id = 123;'
- {{database_context}}: 'PostgreSQL 14, tables: orders, customers'
- {{performance_goals}}: 'Reduce query time from 2s to under 500ms'
Open this prompt Analysis · Intermediate
Analyze Query Performance Trends
Use this when you need to analyze historical query performance data to identify bottlenecks and optimization opportunities.
Open this prompt Analysis · Intermediate
Caching Strategy Recommendations
Use this when you need to identify which queries to cache and how to implement caching to improve query response times.
Open this prompt Analysis · Advanced
Data Aggregation Query Optimization
Use this when you need to optimize data aggregation queries for better performance and efficiency.
Open this prompt Writing · Intermediate
Indexing Strategy Recommendation
Use this when you need to analyze and improve your database indexing strategy to boost query performance.
Open this prompt Analysis · Advanced
Join Optimization Strategy
Use this when you need to improve the performance of SQL queries by optimizing join operations.
Open this prompt Analysis · Advanced
Optimize Query Parameters
Use this when you need to fine-tune query parameters like filter conditions or hints to improve performance.
Open this prompt Analysis · Intermediate
Optimize SQL Queries with Tools
Use this when you need to identify and resolve SQL query performance bottlenecks using optimization tools.
Open this prompt Analysis · Intermediate
Optimize Subqueries for Performance
Use this when you need to optimize subqueries within larger SQL queries to improve overall performance.
Open this prompt Writing · Advanced
Parallelize Queries for Speed
Use this when you want to speed up query execution by leveraging parallel processing techniques.
Open this prompt Planning · Advanced
Partitioning Strategy Recommendation
Use this when you need to design a partitioning strategy for large datasets to improve query performance and manageability.
Open this prompt Planning · Advanced
Profile Resource-Intensive Queries
Use this when you need to identify and optimize resource-intensive database queries to improve system performance.
Open this prompt Analysis · Intermediate
Query Cache Utilization Plan
Use this when you need to identify which queries to cache and how to improve cache hit rates for better performance.
Open this prompt Analysis · Intermediate
Query Cost Estimation Framework
Use this when you need to estimate the execution cost of SQL queries and identify optimization opportunities.
Open this prompt Analysis · Advanced
Query Optimization Best Practices
Use this when you need a comprehensive guide to optimizing data queries, including indexing, query plan analysis, and common pitfalls.
Open this prompt Learning · Intermediate
Rewrite Queries for Efficiency
Use this when you need to rewrite complex SQL queries to improve execution time and resource usage.
Open this prompt Writing · Intermediate