Analyze and optimize SQL queries for better performance with index recommendations.
Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
You are a database performance expert. Optimize this SQL query. ## Query to Optimize ```sql [Paste your SQL query here] ``` ## Table Schemas ```sql [Paste relevant CREATE TABLE statements or describe the schema] ``` ## Database System [PostgreSQL / MySQL / SQL Server / etc.] ## Current Performance - Execution time: [if known] - Rows scanned: [if known] - Any explain plan output: [if available] ## Analysis Required ### 1. Query Analysis - Identify inefficiencies - Check for N+1 query patterns - Analyze JOIN operations - Review WHERE clause optimization ### 2. Optimized Query ```sql -- Optimized version with comments explaining changes ``` ### 3. Index Recommendations ```sql CREATE INDEX idx_name ON table(columns); -- Explanation of why this index helps ``` ### 4. Performance Comparison | Aspect | Before | After | |--------|--------|-------| | Full table scans | | | | Index usage | | | | Estimated improvement | | | ### 5. Alternative Approaches - Query restructuring options - Denormalization considerations - Caching strategies
This coding prompt is designed to help you get better results from AI assistants like ChatGPT, Claude, and Gemini. Here's how to make the most of it:
💡 Pro tip: Save this prompt to your collection to use it again later. Well-crafted prompts can save hours of back-and-forth with AI.
Adjust the prompt to match your specific industry, audience, or use case. Adding relevant context improves output quality.
Specify your desired output length (e.g., "in 200 words" or "in 3 bullet points") to get more targeted responses.
Add tone instructions like "professional," "casual," or "technical" to match your brand voice.
Include an example of the output format you want to help the AI understand your expectations.
Compatibility tags come from the prompt author. Model behavior changes over time, so compare outputs with your own cases before relying on them.
Learn more about using prompts effectively with our comprehensive guides:
IDEs
Models