I have many slow queries. It appears when I search for a photo in a media gallery:

# Time: 2017-07-02T10:04:13.180832Z
# User@Host: site_234[site_234] @ localhost []  Id: 1226011
# Query_time: 2.109665  Lock_time: 0.000051 Rows_sent: 3  Rows_examined: 183299
SET timestamp=1498989853;
SELECT ID FROM wp_posts where guid = 'https://example.org/uploads/500.jpg' AND post_type = 'attachment';

I believed that the slow queries are coming from querying for attachments. How can this problem be solved? I have a lot of photos.

1 Answer 1


This is bug #31071: media / post_mime_type related queries are very slow on larger sites. It should have been fixed for version 4.8 now.

You can try it on a test site that is a mirror of your production site. There are some very interesting ideas in that bug discussion. See if you can use some of them right now already, like adding an index.

  • I now have version 4.8 Jul 2, 2017 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.