Legacy SQL Review
Use this skill when reviewing SQL in legacy or enterprise systems, especially where mapper frameworks and vendor-specific database behavior matter.
Review Priorities
- Correctness and data integrity
- Missing or unsafe parameter binding
- Pagination and ordering stability
- Performance risks such as repeated subqueries, non-sargable predicates, or unnecessary DISTINCT/UNION
- Hard-coded locale, code, or environment assumptions
- Maintainability and mapper readability
Procedure
- Identify the purpose of the query and the expected result shape.
- Review joins, filters, grouping, and ordering for correctness.
- Check parameter binding and dynamic SQL behavior.
- Look for vendor-specific edge cases such as pagination, null handling, or optimizer-hostile patterns.
- Recommend concrete rewrites or targeted experiments when the issue is not provable from static review alone.
Output Format
- Query goal
- Findings by severity
- Performance observations
- Binding and safety observations
- Suggested rewrite or validation steps
- Test data or execution scenarios worth checking
Rules
- Be explicit when a concern is static evidence versus execution-plan speculation.
- Prefer practical rewrites over abstract style criticism.
- Highlight missing tests for edge-case data, pagination, and empty-result behavior.