Audits
How the database query efficiency audit works
See how Enji Guard traces avoidable database work in important application workflows.
Audit page Database query efficiency auditWhat this audit answers
How efficiently does the application use its database in important workflows? Frequent operations, resource-heavy background jobs, and significant workflows that run infrequently can all matter.
What Enji Guard inspects
Enji Guard follows applications, workers, scheduled jobs, and shared data access layers from callers to queries and back to consumers. It inspects declared schemas, migrations, indexes, and store-specific behavior. That includes dynamic query construction and implicit ORM loads where applicable.
The audit uses call sites, loops, schedules, and available measurements to establish why a path matters. For example, it checks whether a related-data lookup runs for every item, what bounds the number of items, and what data the caller actually needs.
Diagnostic criteria
The report rates applicable criteria from 0 to 5. An inapplicable criterion or one with insufficient evidence has an explanation in place of a rating.
- Indexes. Compare declared indexes with filters, joins, sorting, and the access patterns they need to support.
- Filtering and joins. Check predicates, conversions, and unnecessary intermediate rows.
- Related data. Trace N+1 reads and establish how query count grows.
- Repeated reads. Check whether repeated lookups or counts serve different purposes or freshness needs.
- Result volume. Match loaded rows, fields, and related objects to their use and effective limits.
- Pagination and traversal. Inspect offsets, ordering, batch bounds, counts, and intentionally complete operations such as exports.
- Sorting and aggregation. Follow how much data moves and where it is processed.
- Writes and bulk operations. Trace redundant updates or per-item writes while accounting for constraints, hooks, and required side effects.
How evidence becomes findings
A finding identifies a reachable operation, the query and relevant schema or index, the unnecessary work, and the conditions that affect its cost. The structured report includes a summary, findings with evidence and confidence, diagnostic criteria, recommendations, scope limits, and a score when supported. A recommendation identifies what should change and how to verify that the operation still behaves as intended.
Low covers small avoidable work. Medium covers a bounded inefficiency with concrete impact. High requires substantial avoidable work on a hot path, an important workflow, or across many operations. Critical requires evidence that a normally reachable operation can exhaust shared database resources and make the core system unavailable despite applicable safeguards. A missing index or N+1 pattern needs evidence of the actual consequences for the claimed severity. Unconfirmed opportunities can appear as Info.
How the score works
Enji Guard calculates scores the same way across audits. The calculation starts at 100 and deducts 25 points per Critical finding, 14 per High, 7 per Medium, and 3 per Low. Info findings deduct zero. The calculation counts each independent root cause once when the evidence supports medium or high confidence. One Critical or at least two High findings cap the result at 69. The final score stays within 0–100. Diagnostic criterion ratings do not enter the calculation.
Limitations and boundaries
This is a read-only, code-first assessment. A declared schema describes the repository revision. Deployed indexes, optimizer plans, cardinality, and latency require separate evidence. An optional local database check uses synthetic data, and any measurement applies to that setup. The audit leaves index changes and production checks to the team.
Review and rerun
Use the finding to verify the expected query count or result size, along with the operation’s results and side effects. Rerun against the revised commit and use measurements from the relevant environment if you need to quantify the performance effect.
Enji Guard