toolcacheAI Coding Prompts › SQL Query Optimisation Guide

SQL Query Optimisation Guide

Help me write and optimise SQL queries for better performance.

Database: [POSTGRESQL / MYSQL / SQLITE / SQL SERVER]
Problem: [SLOW QUERIES / COMPLEX JOINS / NEED TO LEARN / OPTIMISATION]
Table sizes: [APPROXIMATE ROW COUNTS]

Provide:
1. **Query Analysis**: How to use EXPLAIN to understand query performance
2. **Index Strategy**: Which columns to index and what type of index
3. **Join Optimisation**: How to write efficient joins
4. **Subquery vs Join**: When to use subqueries vs joins
5. **Aggregation Performance**: Optimising GROUP BY and aggregate functions
6. **Pagination**: Efficient pagination for large datasets
7. **Common Table Expressions**: Using CTEs for readable complex queries
8. **Window Functions**: Practical uses for ROW_NUMBER, RANK, PARTITION BY
9. **Query Rewriting**: 5 common slow query patterns and their fast alternatives
10. **Monitoring**: How to identify slow queries in production
🔒

Unlock this prompt

You have 5 free unlocks remaining

or
Get unlimited access from £2.99 →

How to use this prompt

Copy the prompt above and paste it into ChatGPT, Claude, Gemini, or any AI assistant. Replace the bracketed placeholders with your specific details.

Leave a Review

Tried this prompt? Let us know how it worked — your reviews help other users find the best prompts.

Get Unlimited Access →Browse All 2,400 Prompts