An endpoint is slow, and the first proposal is to split the service. Then come a cache in front, a queue beside it, and a new boundary because the current one feels awkward. The slow log is only a list of statements that crossed a time threshold. It does not judge the service. If you refactor first, you usually move the same statement into a place with worse visibility and the same Rows_examined.

Use a fixed order before that refactor. Start with the wait a person already feels. Find the statements from that time window. Group them by SQL text. Compare Rows_examined with Rows_sent. Count repetitions. Only then choose the change: an index, one aggregating query instead of a loop, a smaller payload, or work that truly should leave the request path. The numbers below belong to single operations on one training platform. They are not a multiplier for your system and did not come from splitting that platform apart.

1. What one log entry is actually saying

A MySQL slow log entry has a header and a statement. The header shows a timestamp, user and host, Query_time, Lock_time, Rows_sent, and Rows_examined. Then comes the SQL. Query_time is the time for that statement, not the full wait a person felt. Lock_time is the part spent waiting on a lock. Rows_sent is what the server returned. Rows_examined is how many rows the server had to inspect to do that.

The ratio is the first cut. If a statement examines a few hundred thousand rows to send twenty, the access path is wrong. Common causes are a missing index, a leading wildcard, a function wrapped around the column, or a join that multiplies rows before filtering. None of that proves the service boundary is wrong. A split leaves the statement intact. You will read the same ratio in two repositories instead of one.

If Lock_time is close to Query_time, another writer is holding the row. A new service that takes the same locks only adds a network hop. Find the competing writer before you redraw the diagram.

Read a single entry with this in front of you:

2. The log under-reports a loop

long_query_time is a threshold. A statement below it stays invisible. A page that runs a 200 ms query once per row can keep a person waiting for many seconds while the slow log stays quiet, because each execution is still under the threshold. If the person waited twelve seconds and the log shows one short statement, count repetitions before you decide the request is explained. The framework query log, or a sample with a lower threshold on a copy, will show the loop the slow log skipped.

On one training platform, “the platform is slow” never helped. A loop of database queries became one aggregating query. That operation dropped from 12.41 seconds to 2.451 seconds, and memory use fell by 1.5 GB. The repetition was the bug. If the new query still examined the wrong rows, the time would have stayed high. The refactor that would have missed the issue is the one that moves the loop into a worker and calls the endpoint fast.

Group the time window by statement text and ignore literals that change per row. Fifty lines that differ only by id are one statement. Write the count next to Query_time. If the count is the problem, replace the loop with one aggregating query. If one execution examines far too many rows, change the index or the predicate. A service split is a third kind of change, and neither of the first two implies it.

3. EXPLAIN on a copy, then the change

Run EXPLAIN on a database with the same shape and serious volume, away from customer traffic. An empty schema can choose a different plan. Running the experiment on production is how people “just take a look” at the copy that accepts orders. If the only MySQL you can read is the live one, take a replica or a restore first. Adding an index is a write. On a large table, that write can take time.

Read the plan against the statement you already grouped. Note the access type, the key used, and the expected rows examined. No key on the selective predicate means a candidate index. A key that still examines a huge number of rows means the predicate does not match the key, or the statement asks for a sort or a leading wildcard the key cannot serve. Write that sentence down. An index that does not match that sentence is a key nobody uses.

Missing search indexes were part of the same training-platform work. Weekly average CPU load fell from 82.2% to 2.75% after those bottlenecks, including the indexes, were fixed. That number is a weekly average on that platform. It is not what one EXPLAIN prints, nor a forecast for your CPU. The log and the plan told you where to look. CPU moved because the statements stopped doing wasteful work, not because someone renamed a service.

If a second environment does not exist yet, build the copy before the index. The surrounding release decision, for the people who will feel it, is do not find this out on production.

4. What the slow log will not justify

It will not justify a queue in front of a statement you have not read. A background job that runs the same loop still examines the same rows. The spinner turns into a “processing” badge. The wait simply moved. A queue is the right boundary when the cost is work that should not hold the request, and a retry must not repeat the side effect. That is a different decision from hiding a slow query. Read the statement first. The boundary is in when a Node queue belongs beside Laravel.

It will not justify caching the slow result as the first move. You will store the shape the loop happened to return and invent invalidation for a result you could have computed once. Cache the aggregating query after you measure it. Do not cache instead of writing it.

The log also will not show the response the handler builds. On that training platform, another critical operation dropped from 23,937 ms to 48 ms, and one API response shrank from 912 KB to 2.1 KB. The response cut is not a slow-log line. The page did not need the rest of the record. A refactor that still selects every column sends the same payload across a new boundary. Read the log, then read what the action returns. Both numbers stay attached to those operations. Neither means the whole platform became a fixed number of times faster.

It will not justify a framework rewrite. Inherited production systems were stabilized by changing query shape, indexes, and payload size. If the proposal is “the service is messy, so we rewrite,” ask for the statement, the row counts, and the seconds first. Messy code that runs one indexed query is maintenance work. It is not today’s incident.

5. A reading order you can repeat

Pick the page or job a person already waits on. Write the seconds yourself. Pull the slow log for that window, and if the seconds do not add up, pull the statements the threshold hid. Group by SQL text. For the top statement, write Query_time, Lock_time, Rows_sent, Rows_examined, and the repetition count. Run EXPLAIN on a copy. Change one thing: the loop into one aggregating query, the missing index, or the columns you did not need. Measure the same operation again. Keep the log line next to the number.

Without the log fields, the first step is still name the page before you redesign anything. If the wait is a CRM report, ask whether the rows belong to that customer: reports without a rewrite. A faster statement that returns another customer’s rows is not an improvement.

When to ask for a second look

You can group a log and write the row counts without another person. Ask for help when the log sits on a server nobody on the team can read, when EXPLAIN needs a production-sized copy you do not have, or when the statement lives inside a service you are about to replace and the replacement plan never mentions Rows_examined. Send the page, the seconds, and the SQL with those counts. Do not send a raw log that still contains customer values. Strip the literals.

That reading, and the change that follows it, is work I do on systems already in production. Services cover performance work and backend systems. Selected work keeps each number next to the operation that produced it: the aggregating query, the indexes, the response size. A slow log is a list of statements, and the statement it names is where performance and scalability starts. If you have the statement and the counts, write to me and send those. Leave the customer rows out.