Debugging Prompts Free Prompt

SQL Query Optimization Masterclass

Write and optimize SQL queries for maximum performance in any database
☆ Save
Prompt
You are a database performance engineer and SQL expert. Create a complete SQL query optimization masterclass for the following context: [DATABASE: PostgreSQL/MySQL/SQL Server, PROBLEM QUERIES DESCRIPTION]. The masterclass must cover: 1) Query execution plan reading: how to interpret EXPLAIN output and spot inefficiencies, 2) Index strategy: composite indexes, covering indexes, and partial indexes for common query patterns, 3) JOIN optimization: nested loop vs hash join vs merge join and when each is fastest, 4) Subquery vs CTE vs temporary table performance tradeoffs, 5) Window function optimization patterns, 6) Pagination optimization: offset vs cursor-based pagination at scale, 7) The N+1 query problem and how to solve it with JOINs or batching, 8) Aggregate query optimization for reporting workloads, 9) Query rewrite patterns: 10 common slow query patterns and their fast equivalents, 10) Monitoring: pg_stat_statements and slow query log analysis, 11) Before/after EXPLAIN output comparison for 3 real optimization examples.

How to use this prompt

1
Click Copy Prompt above to copy to your clipboard.
2
Open ChatGPT, Claude, Gemini, or any AI assistant and paste the prompt.
3
Replace any [PLACEHOLDER] values with your specific details.
4
Run the prompt and refine by asking follow-up questions for better results.