Expand description
N+1 Query Detection for SQLModel Rust.
This module provides detection and warning for the N+1 query anti-pattern, which occurs when code loads N objects and then lazily loads a relationship for each, resulting in N+1 database queries instead of 2.
§Example
ⓘ
// Enable N+1 detection
session.enable_n1_detection(3); // Warn after 3 lazy loads
// This will trigger a warning:
for hero in &mut heroes {
hero.team.load(&mut session).await?; // N queries!
}
// This is the fix:
session.load_many(&mut heroes, |h| &mut h.team).await?; // 1 queryStructs§
- Call
Site - Information about where a lazy load was triggered.
- N1Detection
Scope - Scope helper for N+1 detection tracking.
- N1Query
Tracker - Tracks lazy load queries for N+1 detection.
- N1Stats
- Statistics about N+1 detection.