Ask questionsQuery with meta_value slowing down database

  • [x] I've read and understood the contribution guidelines.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened.

We had to deactivate Yoast Plugin because with the count of near to 200.000 posts (around 800.000 rows in posts) and around 730.000 ( 365.000 _wp_attached_file ) post_meta rows it was slowing down the server from 25% to 75% database load and more.

We tracked it down to this query that seems to come from you plugin:

SELECT post_id FROM postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = '2017/06/vers1-1.jpg'

Seems be be the image of twitter cards.

We did not look into you code, but with deactivating Yoast Plugin all went back to normal.

Please describe what you expected to happen and why.

I think searching in the not indexable post_meta.meta_value field should be moved elsewhere for performance reasons. Perhaps it is possible to store the post ID for the attachment in the wp_options or something like this.

How can we reproduce this behavior?

  1. Make a lot of posts with a lot of attachements
  2. Get a lot of visitors
  3. Than you will see that the exact same query I talked about earlier is executing very long and at every pageimpression

Technical info

  • WordPress version: 4.9.6
  • Yoast SEO version: 7.7
  • Depending Plugins: Yoast SEO: News

Answer questions raptor235


I'm still seeing this issue with premium 12.3 version...

<img src=''/>

query monitor is reporting the slow query

<img src=''/>


Related questions

An error occurred loading the Yoast SEO primary taxonomy picker hot 2
Notice: Undefined index: premium-free-translations.php hot 1
Custom Post Types CPT fail to output Article Schema and show Webpage hot 1
Warning: array_merge(): Arguments #1 &#2 are not arrays in class-wpseo-options.php on line 187 hot 1
Visual Composer no getting load in latest wordpress hot 1
Notice: Undefined index: premium-free-translations.php hot 1
Yoast SEO Meta Box Blank (due to issues with Avada?) hot 1
An error occurred loading the Yoast SEO primary taxonomy picker hot 1
textLength error hot 1
Github User Rank List