What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
To find a slow MySQL query in Laravel, first observe SQL activity in the request with Laravel’s query hooks or collect server-side evidence with MySQL’s slow query log. Then inspect the actual statement with EXPLAIN, make one targeted change, and measure again. Laravel monitoring helps connect database work to a request; EXPLAIN helps assess how MySQL will execute a statement.
Start by locating the time-consuming database work
First determine whether database activity is a meaningful contributor to the slow request. Laravel offers two useful query-monitoring hooks, but they answer different questions:
DB::listenlets you observe individual SQL query events executed by the application. Use it in a controlled diagnostic or development context to inspect the statements and their timings, and to spot repeated or unexpectedly costly queries.whenQueryingForLongerThanruns a callback when the cumulative time spent querying during one request exceeds a threshold you set in milliseconds. It can flag a database-heavy request even when no single query exceeds that threshold.
Laravel also documents db:monitor, which can dispatch a database-busy event when open connections exceed a configured count. That is a connection-pressure signal, not evidence that a particular SQL statement is slow. See Laravel’s database documentation for the framework’s query callbacks and database monitoring.
Query timings do not represent the request’s full response time. If the database work appears modest, investigate the rest of the request as well; application code outside SQL can also contribute to latency.
#1 Best Overall
Choose the right evidence: Laravel hooks, slow log, or both
| Tool | What it shows | Best use |
|---|---|---|
| Laravel query hooks | Individual query events or cumulative query time within an application request | Connecting database activity to a Laravel request and spotting repeated queries |
| MySQL slow query log | Server-side statements that meet the configured time and row-examination criteria | Collecting database evidence for statements that cross server thresholds |
EXPLAIN |
The optimizer’s execution plan for a statement | Assessing whether the selected plan and indexes fit the query |
The slow query log is disabled by default in MySQL 8.0. It records statements according to long_query_time and min_examined_row_limit; the documented MySQL 8.0 default for long_query_time is 10 seconds. That is a server default, not a recommended Laravel response-time budget or a universal definition of a slow query. Check the settings for your MySQL release and hosting environment. See the MySQL 8.0 slow query log documentation and MySQL 8.0 server system variables.
MySQL can also log queries that do not use indexes through log_queries_not_using_indexes. The manual warns that this can make the log grow quickly and describes throttling. Treat changes to slow-log settings as operational decisions: scope them, monitor log volume, and revert them when appropriate.
Rank #2
Inspect the actual statement and its execution plan
Once you have a candidate, capture the SQL and its bindings, then run EXPLAIN on a representative statement. The plan shows the operations MySQL selects to execute it, including indexes considered or used. Review the plan alongside the statement’s filters, joins, sorting, and the distribution of data; do not decide on a fix from one plan field in isolation. See MySQL’s explanation of execution plans.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →For a slow SELECT ... WHERE query, MySQL’s optimization guidance says to check whether an index can help, including on columns used in the WHERE clause. It also advises minimizing full table scans on large tables, examining expensive expressions, and keeping table statistics current with ANALYZE TABLE where appropriate. These are investigation paths, not a rule to index every filtered column. Consult MySQL’s SELECT optimization guidance, using documentation that matches your MySQL release.
Make one targeted change, then validate it
Use the query and plan to state a specific hypothesis before changing anything. Possible areas to investigate include a missing or unsuitable index, retrieving more rows or columns than needed, an expensive expression, or another query-shape issue. The right fix depends on your statement, schema, data, and workload; there is no universally correct index or rewrite for Laravel queries.
- Record a baseline. Note the request behavior, the statement, and its plan under conditions representative of the workload you care about.
- Change one thing. Make a targeted query or schema adjustment that tests the hypothesis, rather than combining several changes that make the result hard to interpret.
- Compare the result. Recheck the plan and behavior with representative data. Consider both read performance and the storage and write work an index adds.
- Verify the request path. Confirm that the Laravel request issues the intended number of queries and that database activity improves under the relevant conditions.
A plan or latency result from one dataset is not proof that a change will help every workload. Keep the test conditions in mind when deciding whether to retain the change.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Use thresholds that fit your application
Laravel’s cumulative query callback accepts a threshold in milliseconds, while MySQL’s slow log uses server-side thresholds and row-examination criteria. Neither framework documentation nor MySQL’s documented default establishes the right threshold for a particular application. Choose values in light of the latency objective and the evidence you need, then verify that the monitoring produces useful results without creating an operational burden.
Laravel’s relevant documentation is for version 13.x. If your project uses an earlier release, check its installed framework version and documentation before copying an API example. MySQL defaults and available controls can also vary by server release and hosting environment.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

