Debugging workflows
Trace query cost back to Laravel code
Start with the request’s database shape, separate repeated work from slow work, and use bindings and application call sites to find the cause.
Triage the database work
-
Confirm the request
Match the method and path first. A background request can have a completely different query profile. -
Compare count and total time
Many fast queries suggest repeated application work. A few expensive queries suggest database planning, indexing, locking, or transferred data. -
Open findings and query groups
Use slow, repeated, and likely N+1 findings as shortcuts into the retained query evidence.
Investigate repeated queries and likely N+1 work
New Debug Bar groups queries with the same normalized SQL shape. Different bindings can reveal a loop that loads one related record at a time.
- Check whether the repeated group grows with the number of models shown on the page.
- Compare bindings to see whether only an identifier changes between calls.
- Open the application call site and inspect the surrounding loop, resource, accessor, view, or relationship access.
- Look at the Models and Views sections for repeated retrieval or rendering that explains the query pattern.
Inspect a slow query
Open the query detail and keep its SQL, bindings, duration, connection, and source together. Copy the bound query when you need to reproduce the exact local case.
Use the EXPLAIN action to inspect the database plan for supported read queries. Look for a large scanned row count, an unexpected full scan, a costly sort, or an index that does not match the filters and ordering.
Find the application source
The source location and short application stack are usually more useful than the SQL text by itself. They show the controller, service, model, resource, or view path that caused the query.
If the first frame is shared infrastructure, move down the retained application frames until you reach the caller that controls the work. Then inspect nearby relationship access, conditional loads, pagination, aggregates, or repeated helper calls.
Verify the fix on the same path
- Repeat the same action with comparable records and a warm application.
- Confirm the repeated group or slow query disappeared for the intended reason.
- Check total query count, total query time, request duration, and returned behavior.
- Add a focused profile assertion when the query budget protects an important path.
Next step
Look beyond SQL
Use the timeline, request duration, HTTP calls, rendering, and memory when database time does not explain the page.
Open the performance guide