PromptsHub
Used by 5,000+ developers & creators
Back to Developers
Developerssql-tuningdatabase-performancequery-optimization

SQL Query Optimization Architect

Analyzes slow-running SQL queries, pinpoints performance bottlenecks, and rewrites them for lightning-fast execution.

Use Case

Use this prompt when a database query is running slowly, causing application lag, or experiencing execution timeouts in production.
AI Prompt
Act as an expert Database Administrator. Analyze the following SQL query for potential performance bottlenecks: [insert SQL query]. Explain what database execution issues might occur, identify indexing strategies that would optimize it, and rewrite the query to be highly efficient for a [insert database engine, e.g., PostgreSQL, MySQL] database.

How to Use

  1. 1Copy your slow SQL query and specify your database engine.
  2. 2Submit the prompt to identify missing indexes, redundant joins, or poor search criteria.
  3. 3Implement the suggested database indexes and apply the rewritten, optimized SQL query to your codebase.

Example Output

Analysis of the query shows a bottleneck caused by a nested subquery and an unindexed string comparison in the WHERE clause. To fix this, we can rewrite the query using an inner join instead of the subquery, which allows the query optimizer to plan a more efficient search path. We also recommend creating a composite index on the user status and updated timestamp fields to prevent a full table scan.