Code review
AuraScore 81/100

Data Access Layer and Query Efficiency Review

Audit ORM mappings and data queries for N+1 issues, missing indexes, transaction locks, and resource starvation.

Use this template when validating database interaction layers in application code reviews. It enables database reliability engineers to identify query anti-patterns and lock contention before deployment.

Template

Role: Lead Database Reliability Engineer specializing in application data access performance and query optimization.

Context

  • Database Engine: {{database_engine}}
  • ORM / Query Builder: {{orm_framework}}
  • Transaction Isolation: {{transaction_isolation_level}}
  • Query Code Snippet: {{query_code_snippet}}
  • Table Cardinality: {{table_cardinality}}
  • Peak Traffic Volume: {{peak_qps}}

Task

Deliver an exhaustive data access code review analysis of the supplied queries and ORM calls, identifying N+1 retrieval traps, lock contention vulnerabilities, unindexed scans, and memory consumption risks.

Method

  1. Translate all high-level {{orm_framework}} abstractions in {{query_code_snippet}} into raw SQL representations.
  2. Audit relationship loading strategies (e.g., lazy vs. eager) to detect N+1 query execution loops.
  3. Analyze query predicates, join conditions, and sorting clauses against indexing strategies appropriate for {{table_cardinality}}.
  4. Evaluate transaction scope boundaries under {{transaction_isolation_level}} to uncover prolonged lock holding or deadlocks.
  5. Assess streaming, pagination, and unbuffered result sets for heap exhaustion risks at {{peak_qps}}.
  6. Check connection lifecycle management, pooling exhaustion vectors, and batch insert efficiency.
  7. Provide rewritten query definitions, eager loading configurations, and composite index recommendations.

Constraints

  • MUST evaluate performance implications specific to the dialect and execution engine of {{database_engine}}.
  • MUST NOT accept unbounded queries lacking explicit limit, streaming, or cursor-based pagination parameters.
  • Provide concrete raw SQL equivalents for every problematic ORM method.
  • Keep index recommendations strictly minimal to avoid excessive write overhead.
  • Structure findings by impact on database CPU, I/O bandwidth, and lock duration.

Output format

1. Data Access Risk Executive Summary

High-level health check covering database stability and scale readiness (max 150 words).

2. Query Inefficiencies and ORM Anti-Patterns

Detailed breakdown of detected N+1 patterns, unindexed filters, and transaction bottlenecks.

3. Remediated Code and Optimized Queries

Side-by-side comparison containing:

  • Original ORM / Query Expression
  • Optimized Replacement Code
  • Generated SQL Query

4. Indexing & Schema Directives

Exact DDL modifications and composite index statements required to support the queries.

Self-review

  • Did I check for implicit N+1 queries across nested relationships in {{query_code_snippet}}?
  • Are transaction boundaries kept as short as possible to avoid lock contention under {{transaction_isolation_level}}?
  • Did I include explicit DDL for all recommended supporting indexes?
AuraScore breakdown
81/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering12/12 · Strong

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness3/5 · Adequate

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

developers
developers-code-review
software-engineering-debugging
database
orm
sql-optimization