SQL Review Prompt: Query Plans and Measured Improvements
Review a query using its schema, database version and execution evidence. Compare result correctness and measured performance before adopting changes.
Illustrative cover; not a verified result from this prompt.
Read the full prompt
Review this SQL query for [DATABASE AND VERSION]: [QUERY]. Schema, indexes, row counts and representative execution plan: [DETAILS]. Explain likely bottlenecks using the supplied evidence. Suggest a minimal rewrite or index and describe read, write and storage tradeoffs. Preserve result semantics. If measurements are absent, provide a safe comparison procedure rather than invented before-and-after timings. Mark assumptions about data distribution. Do not recommend destructive schema changes or production execution without a reviewed migration plan.
Include the schema and query plan
A query can be slow for different reasons on different data. Supply existing indexes, approximate row counts and the database version. Remove personal values from examples. Distinguish an estimated plan from an execution that actually ran.
Example: recent orders for one customer
Consider “SELECT id, created_at FROM orders WHERE customer_id = 42 ORDER BY created_at DESC LIMIT 20.” Ask whether an index beginning with customer_id and then created_at fits this workload, given the existing indexes and writes. The answer should explain the reasoning, not promise a speedup.
Compare the returned order and row count before comparing elapsed time. Include a customer with no orders and one with many orders in the test dataset.
Measure the tradeoff
Use a representative staging copy and record the same query under comparable conditions. Execution-analysis commands may run the query; treat writes with care. Check insert overhead and storage after adding an index. Reject fabricated benchmark tables and avoid partitioning a table merely because the prompt lists it as an option.