PB-2501: Slow database query
Paul Bunyan code PB-2501 (Warning): Slow database query. What it means and what to do.
On this page
What it means
One query took longer than the slow-query threshold.
What to do
The message names the function and line that ran it. Look for a missing index, a search without limits, or a table that has grown large. A trivial query that is slow points at the database server, not the code.
Common causes
- A search or filter on a column without an index, so the database reads the whole table (PB-2504).
- Meta queries (
postmeta,usermeta, order meta) with several conditions on a large site. - Queries with
LIKE '%term%', or sorting by a calculated value. - A table that grew large over time: logs, sessions, expired transients (PB-3003), or old revisions.
- A busy or undersized database server: then even simple queries are slow.
How to find and fix it
- The message names the function and line that ran the query, and the query's shape with the values removed.
- Check whether the same query is slow every time or only at busy moments. Only at busy moments points at the server.
- If the query filters on a column with no index, add an index or change the query to use one that exists.
- Clean out tables that only grow: old logs, expired transients, spam comments.
- For plugin queries, report the shape and timing to the plugin's author.
Details
| Code | Severity | Group |
|---|---|---|
| PB-2501 | Warning | Database |
