I’m experiencing performance issues on my site, and my host provided me with the following query that continuously runs and causes slowdowns. Killing it only makes it restart immediately.
Query Details:
SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = '_wc_gla_visibility') LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id) LEFT JOIN wp_postmeta AS mt2 ON (wp_posts.ID = mt2.post_id AND mt2.meta_key = '_wc_gla_errors') LEFT JOIN wp_postmeta AS mt3 ON (wp_posts.ID = mt3.post_id) LEFT JOIN wp_postmeta AS mt4 ON (wp_posts.ID = mt4.post_id) LEFT JOIN wp_postmeta AS mt5 ON (wp_posts.ID = mt5.post_id AND mt5.meta_key = '_wc_gla_visibility') LEFT JOIN wp_postmeta AS mt6 ON (wp_posts.ID = mt6.post_id) LEFT JOIN wp_postmeta AS mt7 ON (wp_posts.ID = mt7.post_id AND mt7.meta_key = '_wc_gla_errors') LEFT JOIN wp_postmeta AS mt8 ON (wp_posts.ID = mt8.post_id) LEFT JOIN wp_postmeta AS mt9 ON (wp_posts.ID = mt9.post_id)
Context:
This query seems to be related to WooCommerce Google Listings & Ads (_wc_gla_visibility and _wc_gla_errors are referenced).
The issue is affecting performance, with queries running for long durations.
My host mentioned that it immediately restarts when killed.
What I’ve Tried:
Disabled Google Listings & Ads plugin – The query disappears when the plugin is deactivated.
Checked Scheduled Actions (WP Crontrol) – Found some WooCommerce background tasks but unsure which one is causing this.
Enabled SAVEQUERIES & Debug Log – The query doesn’t show up in WordPress logs, possibly due to being a direct MySQL query.
Questions:
Is this expected behavior for Google Listings & Ads?
How can I stop or optimize this query?
Is there a way to limit how often it runs without breaking product sync?
I understand that a query related to Google for WooCommerce is continuously running, causing performance slowdowns. Disabling the plugin stops the query, but it restarts immediately when enabled. You’ve also checked scheduled actions and debug logs but haven’t identified the exact cause.
Could you share more details on how performance is affected? I want to understand the difference when Google for WooCommerce is enabled and when it is disabled.
Have you tried disabling all plugins except WooCommerce and Google Listings & Ads? This will help determine if another plugin is interfering.
Modifying the plugin’s default behavior isn’t recommended, so I’d like to investigate why this happens with default settings. Please share your site’s System Status Report by pasting it into https://pastebin.com and sharing the link here. This will help me review your setup.
Once I have more information, I will be in a better position to assist you further.
It does still occur when it’s only WooCommerce and Google for WooCommerce. It doesn’t appear to be affected by any other plugins.
The impact on performance is that it creates significant server load which consumes the resources, creating issues for the host as well as on the site. According to our host, it triggers at 5am every day, so my suspicion is that it’s the plugin processing and collating information from all the products in order to sync with the Google Merchant Centre.
I understand that the query consumes significant server resources when it is executed at 5 AM every day. This query may be collecting all the product information to sync with Google Merchant Center.
I noticed that you have 37 products and 2132 product variations. Having a large number of variations may consume more resources than having simple products.
Could you share more details on how much server resources are consumed? This information will help me compare the results of your site with an average site.
Thank you for providing the screenshot, it really helps us understand the impact this issue is having on your site. After reviewing the details internally, our dev team has noted that the SQL query appears to be missing a WHERE clause, which might contribute to the continuous execution and high resource consumption.
To further diagnose this issue, could you please provide us with two key pieces of information?
1. Complete System Status Report (SSR): Please generate your SSR by going to WooCommerce > Status > Get Status > Copy for Support and share it via a persistent service like QuickForget or Pastebin. This will help us review your overall setup and any customizations that might be impacting performance.
2. Full SQL Query Details: Using a plugin like Query Monitor, capture the complete SQL query that’s being executed. Having the full query, including any parts that might be missing from the snippet provided, will help us trace where it originates within the Google for WooCommerce functionality.
Once we have these details, we’ll be in a much better position to pinpoint the cause and advise further on a solution to optimize the performance. Looking forward to your response!
| 12205 | wp_7sokw | localhost | wp_cpzx9 | Query | 5696 | Sending data | SELECT TpIcb_posts.ID FROM TpIcb_posts LEFT JOIN TpIcb_term_relationships ON (TpIcb_posts.ID = TpIcb_term_relationships.object_id) LEFT JOIN TpIcb_postmet a ON ( TpIcb_posts.ID = TpIcb_postmeta.post_id AND TpIcb_postmeta.meta_key = '_wc_gla_visibility' ) LEFT JOIN TpIcb_postmeta AS mt1 ON ( TpIcb_posts.ID = mt1.post_id ) LEFT JOIN TpIcb_postmeta AS mt2 ON ( TpIcb_posts.ID = mt2.post_id AND mt2.meta_key = '_wc_gla_errors' ) LEFT JOIN TpIcb_postmeta AS mt3 ON ( TpIcb_posts.ID = mt3.post_id ) LEFT JOIN TpIcb_postmeta AS mt4 ON ( TpIcb_posts.ID = mt4.post_id ) LEFT JOIN TpIcb_postmeta AS mt5 ON ( TpIcb_posts.ID = mt5.post_id AND mt5.meta_key = '_wc_gla_visibility' ) LEFT JOIN TpIcb_postmeta AS mt6 ON ( TpIcb_posts.ID = mt6.post_id ) LEFT JOIN TpIcb_postmeta AS mt7 ON ( TpIcb_posts.ID = mt7.post_id AND mt7.meta_key = '_wc_gla_errors' ) LEFT JOIN TpIcb_postmeta AS mt8 ON ( TpIcb_posts.ID = mt8.post_id ) LEFT JOIN TpIcb_postmeta AS mt9 ON ( TpIcb_posts.ID = mt9.post_id )
Thanks for providing the requested details! We appreciate your patience and the effort you’ve put into gathering this information.
We’ll be forwarding your system status report, SQL query, and Query Monitor screenshot to our development team for further investigation. Once we have any updates or feedback, we’ll be sure to share them with you as soon as possible.
If you have any additional insights or notice any changes in the meantime, feel free to let us know.
I see this query running on another site. It even more jumbled. The query needs to be fixed. Its left joining to the postmeta without meta_key(in the example I have). It does it down in the where clause. And the joins are multiple times to the same meta key. Why?
SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON ( wp_posts.ID = wp_term_relationships.object_id ) LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = '_wc_gla_visibility' ) LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id) LEFT JOIN wp_postmeta AS mt2 ON ( wp_posts.ID = mt2.post_id AND mt2.meta_key = '_wc_gla_errors' ) LEFT JOIN wp_postmeta AS mt3 ON (wp_posts.ID = mt3.post_id) LEFT JOIN wp_postmeta AS mt4 ON (wp_posts.ID = mt4.post_id) LEFT JOIN wp_postmeta AS mt5 ON ( wp_posts.ID = mt5.post_id AND mt5.meta_key = '_wc_gla_visibility' ) LEFT JOIN wp_postmeta AS mt6 ON (wp_posts.ID = mt6.post_id) LEFT JOIN wp_postmeta AS mt7 ON ( wp_posts.ID = mt7.post_id AND mt7.meta_key = '_wc_gla_errors' ) LEFT JOIN wp_postmeta AS mt8 ON (wp_posts.ID = mt8.post_id) LEFT JOIN wp_postmeta AS mt9 ON (wp_posts.ID = mt9.post_id) WHERE 1 = 1 AND ( ( wp_term_relationships.term_taxonomy_id IN (2, 4) OR NOT EXISTS (SELECT 1 FROM wp_term_relationships INNER JOIN wp_term_taxonomy ON wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id WHERE wp_term_taxonomy.taxonomy = 'product_type' AND wp_term_relationships.object_id = wp_posts.ID) ) ) AND ( ( wp_postmeta.post_id IS NULL OR ( mt1.meta_key = '_wc_gla_visibility' AND mt1.meta_value != 'dont-sync-and-show' ) ) AND ( mt2.post_id IS NULL OR ( mt3.meta_key = '_wc_gla_errors' AND mt3.meta_value = '' ) ) AND ( ( mt4.meta_key = '_wc_gla_synced_at' AND mt4.meta_value < '1740035105' ) ) AND ( mt5.post_id IS NULL OR ( mt6.meta_key = '_wc_gla_visibility' AND mt6.meta_value != 'dont-sync-and-show' ) ) AND ( mt7.post_id IS NULL OR ( mt8.meta_key = '_wc_gla_errors' AND mt8.meta_value = '' ) ) AND ( ( mt9.meta_key = '_wc_gla_synced_at' AND mt9.meta_value < '1740035105' ) ) ) AND wp_posts.post_type IN ('product', 'product_variation') AND ( ( wp_posts.post_status IN( 'publish','draft', 'pending', 'private') ) ) GROUP BY wp_posts.ID limit 300, 100
Here is my first pass, but it can be reduced farther.
SELECT DISTINCT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON ( wp_posts.ID = wp_term_relationships.object_id ) LEFT JOIN wp_postmeta mt1 ON ( wp_posts.ID = mt1.post_id AND mt1.meta_key = '_wc_gla_visibility' ) LEFT JOIN wp_postmeta AS mt2 ON (wp_posts.ID = mt2.post_id) AND mt2.meta_key = '_wc_gla_errors' LEFT JOIN wp_postmeta AS mt3 ON ( wp_posts.ID = mt3.post_id AND mt3.meta_key = '_wc_gla_synced_at' ) WHERE 1 = 1 AND wp_posts.post_type IN ('product', 'product_variation') AND ( ( wp_posts.post_status IN( 'publish','draft', 'pending', 'private') ) ) AND ( ( wp_term_relationships.term_taxonomy_id IN (2, 4) OR NOT EXISTS (SELECT 1 FROM wp_term_relationships INNER JOIN wp_term_taxonomy ON wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id WHERE wp_term_taxonomy.taxonomy = 'product_type' AND wp_term_relationships.object_id = wp_posts.ID) ) ) AND ( ( mt1.post_id IS NULL OR ( IFNULL(mt1.meta_value,'') != 'dont-sync-and-show' ) ) AND ( mt2.post_id IS NULL OR ( mt2.meta_value = '' ) ) AND ( ( IFNULL(mt3.meta_value,'0') < '1740035105' ) ) )
Here’s my second pass, I am not sure some of it, but its super quick. The goal is to remove the group by and not use a distinct. That means removing the left joins because we arent using any of the data in the result set. I dont know the business logic for these queries, but doing these steps for the original developers(not sure who owns this module) will help improve the install base.
On my effected site, the query produces 58k IDs in 2.738 seconds.
SELECT wp_posts.ID FROM wp_posts WHERE 1 = 1 AND wp_posts.post_type IN ('product', 'product_variation') AND wp_posts.post_status IN( 'publish','draft', 'pending', 'private') AND ( # This gets every thing that's a taxonomy of post_type with the EXISTS(SELECT 1 FROM wp_term_relationships WHERE wp_term_relationships.object_id = wp_posts.ID AND wp_term_relationships.term_taxonomy_id IN (2, 4)) #everything thats not a product. This doesnt product anything for me. OR NOT EXISTS (SELECT 1 FROM wp_term_relationships INNER JOIN wp_term_taxonomy ON wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id WHERE wp_term_taxonomy.taxonomy = 'product_type' AND wp_term_relationships.object_id = wp_posts.ID) ) AND ( # dont show sync exists NOT EXISTS(SELECT 1 FROM wp_postmeta mt1 WHERE mt1.post_id = wp_posts.ID AND mt1.meta_key = '_wc_gla_visibility' AND IFNULL(mt1.meta_value,'') != 'dont-sync-and-show' ) # has no errors AND NOT EXISTS(SELECT 1 FROM wp_postmeta mt2 WHERE mt2.post_id = wp_posts.ID AND mt2.meta_key = '_wc_gla_errors' AND IFNULL(mt2.meta_value,'') = '' ) # only hasnt sync'd since a time.
AND NOT EXISTS(SELECT 1 FROM wp_postmeta mt3 WHERE mt3.post_id = wp_posts.ID AND mt3.meta_key = '_wc_gla_errors' AND IFNULL(mt3.meta_value,'0') < '1740035105' ) ) LIMIT 100
This reply was modified 1 year, 2 months ago by pmathbliss. Reason: Add results of the query
Thank you for your message and I appreciate your contribution to this forum.
The suggestions you shared are very helpful. Our developers are looking into the information shared by the thread starter and will post an update here when ready.
If you need assistance, feel free to create a new topic.