Performance bug – slow DB query

It is relatively rare for WP to have query performance issues on a small to moderately sized site:

  1. The queries it typically runs are reasonable (not perfect, but reasonable).
  2. A lot of things queried are aggressively cached within page load, and persistently with object cache available.

While you certainly can throw enough code at it for queries to boggle down, 20s seems extreme. Unless we are talking hundreds of thousands of items.

If the change is sudden as well, I would strongly suspect the issue is on DB server side and tables might need optimize/repair.