• Browse Prompts
  • Trending
  • Saved Prompts
  • Web Dev
  • Marketing
  • Blog
  • Submit Your Prompt
PromptsVault AI LogoPromptsVault AI
  • Browse
  • Trending
  • Blog
  • Saved
  • Submit Your Prompt
PromptsVault AI LogoPromptsVault AI

The world's best AI prompts library. Hand-curated, high-quality prompts for ChatGPT, Claude, and Midjourney. Built for productivity and high-accuracy results.

Categories

  • Web Dev
  • AI/ML
  • Marketing
  • Coding
  • Creative
  • View All →

Popular Topics

  • chatgpt
  • midjourney
  • marketing
  • coding
  • seo
  • writing
  • social media
  • email

Legal

  • About Us
  • AI Blog
  • Privacy
  • Terms
  • Disclaimer

© 2026 PromptsVault AI. All rights reserved.

PromptsVault AI is thinking...

Searching the best prompts from our community

ChatGPTMidjourneyClaude
  1. Home
  2. Library
  3. DATA SCIENCE
  4. SQL query optimization for large datasets
DATA SCIENCE
1 views
AI Prompt for

SQL query optimization for large datasets

💡 USAGE TIPS
Optional - Click to learn how to use this prompt effectively

💡 Pro Developer Tips

Click to view expert tips

Specify framework versions

e.g., 'Next.js 14', 'Python 3.11' for accurate, up-to-date code

Request error handling & types

Ask for TypeScript definitions and try-catch blocks

Get step-by-step breakdowns

Request explanations before code for complex logic

Pro tip: The more context you provide, the better your results!
ACTUAL PROMPT BELOW
PROMPT
Copy & Use FREE

Here is the professional-grade, high-performance prompt. You can copy and paste this directly into your AI tool.


Prompt: SQL Performance Tuning Expert

🎭 Role

Act as a Senior Database Architect and SQL Performance Tuning Specialist. You possess deep expertise in query execution plans, indexing strategies, storage engines (e.g., PostgreSQL, MySQL, SQL Server), and query optimization patterns for multi-terabyte datasets.

🌐 Context

I am currently managing a database containing a table with [TABLE_ROW_COUNT] rows. The current query performance is unacceptable, with execution times exceeding [CURRENT_LATENCY]. The database schema is [DATABASE_ENGINE], and the query is struggling with heavy [JOIN_TYPE/OPERATION_TYPE].

Task

Analyze the provided SQL query and apply advanced optimization techniques to minimize execution time and resource consumption. Your analysis must include:

  1. Bottleneck Identification: Perform a simulated EXPLAIN ANALYZE walkthrough. Identify high-cost operations (e.g., Sequential Scans, Hash Joins, Sort operations).
  2. Indexing Strategy: Propose specific indexes (B-tree, BRIN, GIN, etc.) for WHERE, JOIN, and ORDER BY clauses.
  3. Query Refactoring:
    • Replace inefficient correlated subqueries with Window Functions where applicable.
    • Refactor nested subqueries into CTEs (Common Table Expressions) for readability and potential materialization.
  4. Architectural Improvements: Suggest partitioning strategies (e.g., Range Partitioning by date) or materialized views if the query requires frequent access to historical data.
  5. Validation: Provide a theoretical comparison of execution times (Before vs. After) and justify why the chosen optimization reduces complexity (Big O notation).

⚖️ Constraints & Tone

  • Tone: Professional, technical, and analytical.
  • Brevity: Focus on actionable code and concise reasoning. Avoid fluff.
  • Clarity: Use standard SQL conventions. If using dialect-specific syntax (e.g., T-SQL vs. PL/pgSQL), explicitly state the dialect.
  • Do NOT: Suggest generic advice like "just add an index." Explain why that specific index type is appropriate for the data distribution.

📝 Output Format

  • Phase 1: Diagnosis: A breakdown of why the current query is slow.
  • Phase 2: Optimized Query: The refactored code block with clear comments.
  • Phase 3: Optimization Log: A table or bulleted list mapping each change to the performance benefit gained.
  • Phase 4: Execution Plan Prediction: How the engine should handle the query after changes.

Input Data

[DATABASE_ENGINE]: (e.g., PostgreSQL 15) [TABLE_SCHEMA]: (Paste column names/types or DDL here) [SQL_QUERY]: (Paste the slow query here)


How to use this prompt:

  1. Paste it into your LLM.
  2. Fill in the Input Data section at the bottom before hitting enter.
  3. The AI will now adopt the persona of a Senior Architect and provide a much more structured, engineering-focused solution compared to the original prompt.
Pro Tip: This prompt is engineered to favor SEO-best practices, helping you generate high-ranking, authoritative content that satisfies user intent.
Disclaimer: AI models can hallucinate. Please verify this prompt's output before use. PromptsVault AI is not responsible for AI-generated content.

About This Prompt

What is a good ChatGPT prompt for SQL query optimization for large datasets?

A proven free prompt for SQL query optimization for large datasets is: "Optimize a slow-running SQL query on a 50M+ row table. Techniques to apply: 1. Add appropriate indexes on WHERE and JOIN columns. 2. Replace subqueries with CTEs (Common Table Expressions). 3. Use EXP..." — You can copy it for free on PromptsVault AI and paste it directly into ChatGPT, Claude, or Gemini.

How do I use this DATA SCIENCE AI prompt for SQL query optimization for large datasets?

Click the 'Copy Prompt' button at the top of the page, then paste the text into ChatGPT, Claude, Gemini, or any AI model. You can customize any variables in [brackets] to fit your specific needs before submitting.

Is the SQL query optimization for large datasets prompt free to use?

Yes — this DATA SCIENCE AI prompt is 100% free on PromptsVault AI. No sign-up or payment required. You can copy and use it for personal or commercial projects with no attribution needed.

Which AI tools work best with this SQL query optimization for large datasets prompt?

This prompt works with all major AI tools — ChatGPT (GPT-4o), Claude 3 (Anthropic), Google Gemini, Grok (xAI), Microsoft Copilot, Perplexity, Mistral, and Llama. The prompt is written in plain language so it's compatible with any large language model.

Related Tags

#sql#optimization#database#performance

Advertisement

Join the Community

Submit your prompts and join our elite community of creators!

Submit Now

Related Prompts

D

Google Analytics 4 (GA4) implementation guide

DATA SCIENCE

D

Customer churn prediction model with feature engineering

DATA SCIENCE

D

Jupyter notebook best practices template

DATA SCIENCE

D

A/B test statistical significance calculator

DATA SCIENCE