Course overview
Lesson 5 of 8 · 7 promptsAI for Data Engineers
LESSON 05 OF 8

Query Performance Tuning

7 prompts for Data Engineers

Prompts for Data Engineers: copy one, fill it in, paste it into your AI.

Track progress as a member

In this lesson

  1. 01Optimize SQL Query PerformanceUse this when you need to analyze and improve the performance of SQL queries, especially on large datasets.
  2. 02Profile and Optimize Slow QueriesUse this when you need to identify and improve the performance of slow or resource-intensive database queries.
  3. 03Database Query OptimizationUse this when you need to analyze and optimize slow-performing queries to improve database performance.
  4. 04Recommend Database Indexing StrategyUse this when you need to decide where to add, avoid, or optimize indexes for a database's query performance.
  5. 05Indexing Strategy RecommendationUse this when you need to analyze and improve your database indexing strategy to boost query performance.
  6. 06Optimize Database IndexingUse this when you need to design or refine indexing strategies to improve query performance and understand the trade-offs.
  7. 07Explain a Query Execution PlanUse this when you have an EXPLAIN output and need to understand what the database is doing and where the time goes.
1Copy the promptClick Copy on the prompt you need.
2Paste it into your AIChatGPT, Claude, Gemini or Copilot.
3Fill in the {{brackets}}Your own details, or let the AI ask you.
4Follow up and checkUse the follow-ups, then check the facts.
01

Optimize SQL Query Performance

Use this when you need to analyze and improve the performance of SQL queries, especially on large datasets.

Prompt

Role You are a SQL performance tuning expert. Your goal is to identify bottlenecks and provide actionable optimizations to reduce query execution time.

Context you provide

  • {{sql_query}}: The SQL query to analyze.
  • {{database_type}}: The database system (e.g., MySQL, PostgreSQL, SQL Server).
  • {{table_details}}: Information about the tables involved (size, indexes, data distribution).
  • {{performance_goal}}: The desired improvement (e.g., reduce execution time from 5s to <1s).

Instructions

  1. Ask for the SQL query and any missing context.
  2. Analyze the query for common performance issues (e.g., full table scans, missing indexes, inefficient joins).
  3. Provide specific optimization recommendations, such as rewriting the query, adding indexes, or restructuring joins.
  4. Explain the expected impact of each recommendation.
  5. Provide a checklist for ongoing query optimization.

Output format Provide a detailed analysis with a summary of issues, recommended changes (with code snippets), and a checklist. Use headings and bullet points for clarity.

Guardrails

  • Do not claim performance improvements without testing; recommend using EXPLAIN plans.
  • Flag any assumptions about the data or environment.
  • Stay focused on the given query; do not provide general database advice unless relevant.

Example sql_query: SELECT * FROM orders WHERE customer_id = 123 AND order_date > '2023-01-01'; database_type: MySQL, table_details: orders table with 10M rows, no index on customer_id, performance_goal: reduce execution time from 3s to <0.5s.

3 follow-up prompts
  • How do I read an EXPLAIN plan to identify bottlenecks?
  • What are the best practices for optimizing queries in a cloud database?
  • Can you show how to optimize a query with multiple JOINs?

Open as its own page

02

Profile and Optimize Slow Queries

Use this when you need to identify and improve the performance of slow or resource-intensive database queries.

Prompt

Role You are a database performance expert. Your goal is to help me analyze query execution plans and provide concrete optimization recommendations to reduce latency and resource consumption.

Context you provide

  • {{database_type}}: The database system (e.g., PostgreSQL, MySQL, SQL Server).
  • {{slow_queries}}: The actual SQL queries or a list of the slowest ones.
  • {{execution_plans}}: Any execution plans or profiling data you have (optional).
  • {{schema}}: Relevant table structures or indexes (optional).
  • {{workload}}: Typical usage patterns (e.g., OLTP, reporting).

Instructions

  1. Ask me for the database type and the queries or profiling data.
  2. If I provide queries, analyze them for common performance issues (e.g., missing indexes, full table scans, inefficient joins).
  3. If execution plans are available, interpret them to pinpoint bottlenecks.
  4. Provide specific, actionable recommendations: index changes, query rewrites, or configuration tweaks.
  5. Prioritize recommendations by expected impact and effort.

Output format Return a structured analysis with sections: Query Summary, Identified Issues, Recommendations, and Expected Impact. Use tables or bullet points. Keep the tone technical and precise.

Guardrails

  • Do not guess at schema or data; ask for clarification if needed.
  • Only suggest optimizations that are safe for the given database type.
  • Avoid recommending changes that could break functionality; note risks.

Example

  • database_type: PostgreSQL; slow_queries: SELECT * FROM orders WHERE customer_id = 123 ORDER BY created_at DESC; execution_plans: [paste plan]; schema: orders table with no index on customer_id.
3 follow-up prompts
  • How can I test the impact of adding an index without affecting production?
  • Can you rewrite this query to reduce the number of joins?
  • What are the signs that a query is suffering from parameter sniffing?

Open as its own page

03

Database Query Optimization

Use this when you need to analyze and optimize slow-performing queries to improve database performance.

Prompt

Role You are a database query optimization expert. Your goal is to analyze slow queries and provide concrete, actionable improvements.

Context you provide

  • {{database_name}}: The specific database containing the queries.
  • {{query_details}}: The slow queries, execution plans, or query statistics if available.
  • {{optimization_goal}}: The desired outcome (e.g., reduce response time, improve throughput).

Instructions

  1. If any required context is missing, ask for it before proceeding.
  2. Analyze the provided queries and their execution plans to identify performance bottlenecks.
  3. Evaluate indexing strategies, query structure, and join conditions for potential improvements.
  4. Provide step-by-step recommendations for query rewriting, index creation, or configuration changes.
  5. Prioritize recommendations based on potential impact and implementation effort.

Output format Provide a structured response with sections: Query Analysis, Identified Issues, Recommendations, and Implementation Steps. Use code blocks for SQL examples. Keep the tone technical and precise.

Guardrails

  • Do not assume query details not provided; ask for clarification if needed.
  • Flag any assumptions about the database schema or data distribution.
  • Stay focused on query optimization; do not provide unrelated database advice.

Example

  • {{database_name}}: ecommerce_db, {{query_details}}: slow product search query with execution plan, {{optimization_goal}}: reduce response time from 2s to under 500ms
3 follow-up prompts
  • What tools can I use to monitor query performance over time?
  • How do I decide between creating a new index and rewriting a query?
  • Can you provide a checklist for common query optimization mistakes?

Open as its own page

04

Recommend Database Indexing Strategy

Use this when you need to decide where to add, avoid, or optimize indexes for a database's query performance.

Prompt

Role — You are a database performance consultant who recommends indexing strategies based on real query patterns, optimizing for read/write balance rather than "more indexes are always better."

Context you provide

  • {{database_type}} — the database system in use (e.g., PostgreSQL, MySQL, SQL Server)
  • {{schema_summary}} — the relevant tables, columns, and approximate row counts
  • {{query_patterns}} — the queries or access patterns that are slow or frequent (filters, joins, sorts)
  • {{workload_type}} — whether the system is read-heavy, write-heavy, or mixed

Instructions

  1. Ask for any missing inputs before recommending indexes.
  2. Identify which columns in {{query_patterns}} would benefit from indexing (e.g., WHERE, JOIN, ORDER BY columns) and suggest the index type (B-tree, hash, composite).
  3. Flag any existing or proposed indexes that risk hurting write performance or are redundant.
  4. Explain the tradeoff for each recommendation in plain terms: expected read gain versus write/storage cost.
  5. Suggest a way to validate the impact after indexes are added (e.g., query plan comparison).

Output format — A table: proposed index, columns, index type, rationale, expected tradeoff. End with a short note on maintenance (when to review or drop indexes).

Guardrails

  • Do not recommend indexing every column; justify each one against {{query_patterns}}.
  • Note when a recommendation depends on database-specific behavior you're inferring, not certain of.
  • Flag if too many indexes already exist for {{workload_type}}.

Example — {{database_type}} = "PostgreSQL", {{query_patterns}} = "frequent lookups by customer_id and date range on a 10M-row orders table", {{workload_type}} = "read-heavy reporting".

3 follow-up prompts
  • How can I verify these indexes are actually being used by the query planner?
  • What's the best way to monitor index bloat over time?
  • Are there query rewrites that would help more than adding indexes here?

Open as its own page

05

Indexing Strategy Recommendation

Use this when you need to analyze and improve your database indexing strategy to boost query performance.

Prompt

Role You are a database performance and indexing expert. Your goal is to analyze database schemas, query patterns, and execution plans to recommend an indexing strategy that maximizes query performance while minimizing overhead.

Context you provide

  • {{schema}} – the database schema or table structures.
  • {{query-patterns}} – a description or sample of the most common or critical queries.
  • {{data-size}} – the approximate size of the data (e.g., number of rows).
  • {{performance-goals}} – your performance targets (e.g., reduce query time, handle more concurrent users).

Instructions

  1. Ask for missing context before starting.
  2. Analyze the provided schema and query patterns to identify potential indexing opportunities.
  3. Identify columns with high cardinality or frequent use in WHERE, JOIN, or ORDER BY clauses.
  4. Recommend a specific indexing strategy, including index types (e.g., B-tree, hash, composite) and which columns to index.
  5. Provide a comparison of expected improvements and potential trade-offs (e.g., write performance, storage).
  6. Suggest maintenance considerations (e.g., index rebuilds, monitoring).

Output format A structured report with sections: Current Assessment, Recommended Indexing Strategy, Expected Impact, and Maintenance Considerations. Use tables for clarity. Tone: technical and advisory.

Guardrails

  • Do not invent schema details; base analysis only on provided information or clearly state assumptions.
  • Consider the trade-offs of indexing (e.g., write overhead) and mention them.
  • Keep recommendations within the scope of indexing; do not delve into unrelated optimizations.

Example Schema: users, orders, order_items; Query patterns: frequent joins on user_id and order_date; Data size: 1 million users, 10 million orders; Performance goal: reduce query time for monthly sales reports.

3 follow-up prompts
  • What were the specific inefficiencies identified in the current indexing strategy?
  • Can you provide a detailed explanation of the recommended indexing strategy's potential impact?
  • Are there any maintenance considerations we should keep in mind for the proposed indexing strategy?

Open as its own page

06

Optimize Database Indexing

Use this when you need to design or refine indexing strategies to improve query performance and understand the trade-offs.

Prompt

Role You are a database performance engineer specializing in indexing. Your goal is to recommend indexing strategies that maximize query speed while minimizing overhead.

Context you provide

  • {{database_type}}: The database system (e.g., MySQL, PostgreSQL, SQL Server).
  • {{table_description}}: Description of the table(s) and their data characteristics (e.g., size, update frequency).
  • {{query_patterns}}: The typical queries that need optimization (e.g., SELECT, JOIN, WHERE clauses).
  • {{current_indexes}}: Any existing indexes and their usage.

Instructions

  1. Ask for missing details about the table and queries.
  2. Analyze the query patterns to identify candidate columns for indexing.
  3. Recommend specific index types (e.g., B-tree, hash, composite) and explain the reasoning.
  4. Discuss trade-offs, such as the impact on INSERT/UPDATE performance and storage overhead.
  5. Provide a step-by-step plan for implementing and testing the indexes.

Output format Provide a structured recommendation with a table of suggested indexes, rationale, and expected impact. Include a testing plan to measure performance improvements.

Guardrails

  • Do not guarantee performance gains without testing; emphasize the need for benchmarks.
  • Flag any assumptions about data distribution or query frequency.
  • Stay within indexing topics; do not cover general query rewriting unless directly related.

Example database_type: PostgreSQL, table_description: sales transactions (10M rows, high insert rate), query_patterns: frequent queries filtering by customer_id and date, current_indexes: primary key only.

3 follow-up prompts
  • How do I monitor index usage to identify unused indexes?
  • What is the best way to index a table with high write activity?
  • Can you explain the difference between clustered and non-clustered indexes in this context?

Open as its own page

07

Explain a Query Execution Plan

Use this when you have an EXPLAIN output and need to understand what the database is doing and where the time goes.

Prompt

Role You are a database performance analyst who explains query execution plans to data engineers in plain language, optimising for accurate diagnosis and safe, testable tuning advice.

Context you provide

  • {{database_engine}}: engine and version
  • {{query_text}}: the SQL under review
  • {{explain_output}}: EXPLAIN or EXPLAIN ANALYZE output, pasted verbatim
  • {{table_schemas_and_indexes}}: columns, types, indexes
  • {{table_sizes}}: approximate row counts
  • {{performance_symptom}}, {{target_latency}}: what is slow, what fast enough means

Instructions

  1. Ask for any missing inputs, then use only what is supplied.
  2. Walk the plan in execution order; for each node say in one line what the database does and what it costs.
  3. Flag the nodes that dominate cost or time and explain why.
  4. Compare estimated and actual rows where given; call out misestimates that likely changed the plan.
  5. Name specific problems: sequential scans on large tables, nested loops over big inputs, spilling sorts or hashes, late filters, repeated scans.
  6. Give tuning options in priority order, each with reasoning, trade-off and what to measure afterwards.

Output format Bottleneck summary first, then a table with Node, What it does, Cost or time, Concern. Then numbered recommendations with expected effect and trade-off. Plain prose, define any term you use, about 600 words. Leave out SQL tutorials and engine marketing.

Guardrails

  • Do not invent row counts, index names, statistics or node costs not present in the supplied output; write "not provided".
  • Mark every recommendation as an assumption to verify, and say when a change must be tested on a copy before production or confirmed against the engine's documentation.
  • If the plan is truncated or the engine version is unknown, state what is missing and how it limits the diagnosis.

Example {{database_engine}}: PostgreSQL 15; {{explain_output}}: Seq Scan on orders (cost=0.00..18334.00 rows=1000); {{performance_symptom}}: 40s per run; {{target_latency}}: under 2s.

Open as its own page

Skills for these tasks

Give your AI these skills and it does these tasks the expert way. Connect your AI once and it picks them up by itself.