I see a lot of such queries in "Sending Data" state, using SHOW PROCESSLIST.

Context is a high traffic Wordpress powered news site.

SELECT post_id, meta_value FROM wp_postmeta 
    `meta_key` = '_wp_attached_file' 
    AND LOWER(`meta_value`) IN 
        ('2016/06/file-1.jpg', 'A LONG LIST OF FILES HERE', ... ) LIMIT 76

So far, I have been unable to find what generates these queries. I tried searching for various parts of the query like '_wp_attached_file', 'post_meta' but found no places in the core where this would be generated, nor in my theme or plugins.

  • Some plugin or theme, I guess... It's not native WP query. – Krzysiek Dróżdż Apr 11 '18 at 10:01
  • Any pointers on what would I be searching for? greping for "postmeta" in theme files doesn't seem to bring up anything interesting. – Slavic Apr 11 '18 at 10:04
  • And in plugins? Searching for '_wp_attached_file' could be helpful. – Krzysiek Dróżdż Apr 11 '18 at 10:05
  • 1
    Use the Query Monitor plugin. It'll show you all the queries run for a request, how long they took, and - crucially - where they were made from. – Jacob Peattie Apr 11 '18 at 10:05
  • Found it! It's the Simple LIghtbox plugin. Want to add your comment as an answer Jacob? Thank you very much. – Slavic Apr 11 '18 at 10:55

The problem turned out to be a Lightbox plugin: Simple Lightbox. I used another plugin: Query Monitor to find it, as suggested in the comments by Jacob.

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