PB-2504: Slow query read a whole table
Paul Bunyan code PB-2504 (Warning): Slow query read a whole table. What it means and what to do.
On this page
What it means
A slow query had no index it could use, so the database read every row of a table to find the few it wanted. It gets slower as the table grows.
What to do
The message shows the plan in words: which table, and about how many rows. Add an index on the column the query filters on, or change the query to filter on a column that already has one. For WordPress meta tables, the Index WP MySQL For Speed plugin adds the usual missing indexes.
Common causes
- Searching meta tables by value (
meta_value) instead of by key. - Custom tables created without indexes on the columns used in
WHERE. LIKE '%…%'searches, which can't use an index.- Old tables that never got the indexes newer WordPress versions add.
How to find and fix it
- The message names the table and roughly how many rows the database had to read.
- Add an index on the column the query filters on (take a backup first), or change the query to filter on a column that already has one.
- On large
postmetaorusermetatables, missing indexes are common; adding them is a one-time job. - Check again after the change: the same query should now read a few rows instead of the whole table.
Details
| Code | Severity | Group |
|---|---|---|
| PB-2504 | Warning | Database |
