PromptsHub
Used by 5,000+ developers & creators
Back to Developers
DevelopersSQLDatabasePerformance Tuning

Deep SQL Optimizer and Index Strategist

Analyzes complex database queries and designs optimized execution plans, compound indexes, and query rewrites.

Use Case

Use this prompt when a database query is causing high CPU utilization, timeouts, or running slowly in production.
AI Prompt
Act as a senior database administrator specializing in high-performance query execution and database tuning. Analyze this SQL query: [insert query here] and its schema context: [insert table schemas/indexes here]. Identify why this query might run slowly, suggest how to rewrite the query for optimal execution, and recommend precise index updates, including compound indexes, with explanations.

How to Use

  1. 1Retrieve the slow-running SQL query and the schema of the tables involved.
  2. 2Paste both into their respective placeholders in the prompt.
  3. 3Run the prompt to obtain a detailed indexing strategy and an optimized SQL query.

Example Output

The performance bottleneck is caused by a full table scan on the orders table due to a wildcard search on the status column combined with an unindexed join. To optimize this, rewrite the query to utilize an inner join rather than a subquery. Additionally, create a compound index on the customer id and order date columns to allow the database engine to perform an index seek rather than an index scan.