What this prompt does
Review a SQL query for correctness, security, performance, and maintainability.
Coding
Review a SQL query for correctness, security, performance, and maintainability.
Editorial template. Model evaluation is not recorded; the preview illustrates the intended result. Testing Method
Review a SQL query for correctness, security, performance, and maintainability.
Correctness issues, injection risks, index considerations, rewritten query, EXPLAIN plan checklist, and edge cases.
[SQL][SCHEMA][DATABASE][GOAL]You are a database reviewer. Treat schema and execution-plan facts as unknown unless supplied.
OBJECTIVE: Review [SQL] against [SCHEMA] on [DATABASE] for the goal [GOAL]. INPUTS: SQL: [SQL] SCHEMA: [SCHEMA] DATABASE: [DATABASE] GOAL: [GOAL] OUTPUT CONTRACT: Correctness issues, injection risks, index considerations, rewritten query, EXPLAIN plan checklist, and edge cases.
State the business meaning of the result and provide a tiny fixture with expected rows. Review joins and filters for correctness before discussing performance. Share existing indexes and an execution plan if performance is part of the task. Ask the assistant to distinguish a logical error from an index hypothesis and to preserve the database’s actual behavior.
The blueprint separates authority, task context, evidence limits, and the output contract so requirements can be checked independently.
05
SQL: SELECT customer_id, COUNT(*) FROM orders GROUP BY customer_id SCHEMA: orders(id, customer_id, status) DATABASE: MySQL; supply actual version for a real review GOAL: Count completed orders per customer
06
Correctness finding: The query counts all statuses, not completed orders. Candidate query: SELECT customer_id, COUNT(*) FROM orders WHERE status = 'completed' GROUP BY customer_id; Verification: Use one customer with two completed orders and one canceled order; expected count is two. Performance: Inspect EXPLAIN and representative table sizes before recommending an index. No speedup is measured here.
For a join, include one unmatched row and one relationship with multiple matches. For date filtering, specify the column type and timezone boundary. Keep any proposed index separate from the query correction so you can validate each change independently.
Do not claim a performance improvement without measuring it. A faster query that counts the wrong rows is not a successful optimization.
Editorial blueprint awaiting recorded cross-model evaluation. It is visible for review but is not labeled as tested.
It has passed editorial structure review but does not yet have a published cross-model test record.