Title: Repetitive Database Query Affecting Performance
Last modified: March 7, 2025

---

# Repetitive Database Query Affecting Performance

 *  Resolved [upflowzajayden](https://wordpress.org/support/users/upflowzajayden/)
 * (@upflowzajayden)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/repetitive-database-query-affecting-performance/)
 * 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:**
    1. **Disabled Google Listings & Ads plugin** – The query disappears when the plugin
       is deactivated.
    2. **Checked Scheduled Actions (WP Crontrol)** – Found some WooCommerce background
       tasks but unsure which one is causing this.
    3. **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?**
 * Thanks for any insights!

Viewing 11 replies - 1 through 11 (of 11 total)

 *  [Zee](https://wordpress.org/support/users/doublezed2/)
 * (@doublezed2)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/repetitive-database-query-affecting-performance/#post-18350539)
 * Hello [upflowzajayden](https://wordpress.org/support/users/upflowzajayden/),
 * Thank you for contacting WooCommerce support.
 * 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](https://woocommerce.com/document/understanding-the-woocommerce-system-status-report/#system-status)
   by pasting it into [https://pastebin.com](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.
 * Best regards.
 *  Thread Starter [upflowzajayden](https://wordpress.org/support/users/upflowzajayden/)
 * (@upflowzajayden)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/repetitive-database-query-affecting-performance/#post-18355909)
 * Hi Zubair
 * Thanks for your response
 * 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.
 * Paste: [https://pastebin.com/SP4EfE3Q](https://pastebin.com/SP4EfE3Q) (Note, 
   it will burn after read)
 * Looking forward to any feedback you can provide.
 * Thanks!
 *  [Zee](https://wordpress.org/support/users/doublezed2/)
 * (@doublezed2)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/repetitive-database-query-affecting-performance/#post-18357145)
 * Hello [upflowzajayden](https://wordpress.org/support/users/upflowzajayden/),
 * Thank you for your reply.
 * 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.
 * Looking forward to your response. 🙂
 *  Thread Starter [upflowzajayden](https://wordpress.org/support/users/upflowzajayden/)
 * (@upflowzajayden)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/repetitive-database-query-affecting-performance/#post-18360137)
 * Here is a screenshot from our host showing the resource usage. I hope this helps?
 * ![](https://i0.wp.com/imgur.com/x3wA7F5.jpg?ssl=1)
 * Looking forward to hearing your thoughts.
 *  Plugin Support [LovingBro (woo-hc)](https://wordpress.org/support/users/lovingbro/)
 * (@lovingbro)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/repetitive-database-query-affecting-performance/#post-18368898)
 * Hi [@upflowzajayden](https://wordpress.org/support/users/upflowzajayden/),
 * 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](https://quickforget.com/) or [Pastebin](https://pastebin.com/).
   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!
 *  Thread Starter [upflowzajayden](https://wordpress.org/support/users/upflowzajayden/)
 * (@upflowzajayden)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/repetitive-database-query-affecting-performance/#post-18369186)
 * Thanks so much for the feedback!
 * Here is the system status report: [https://pastebin.com/7sivt3ut](https://pastebin.com/7sivt3ut)
 * And here is the SQL Query:
 *     ```wp-block-code
       | 12205 | wp_7sokw | localhost | wp_cpzx9 | Query | 5696 | Sending data | SELECT TpIcb_posts.IDFROM TpIcb_posts LEFT JOIN TpIcb_term_relationships ON (TpIcb_posts.ID = TpIcb_term_relationships.object_id) LEFT JOIN TpIcb_postmeta 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 ) LEFTJOIN 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 ) LEFTJOIN 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 )
       ```
   
 * And a screenshot from Query Monitor: [https://imgur.com/a/YocrEFf](https://imgur.com/a/YocrEFf)
 * Thanks so much!
    -  This reply was modified 1 year, 2 months ago by [upflowzajayden](https://wordpress.org/support/users/upflowzajayden/).
    -  This reply was modified 1 year, 2 months ago by [upflowzajayden](https://wordpress.org/support/users/upflowzajayden/).
 *  Plugin Support [LovingBro (woo-hc)](https://wordpress.org/support/users/lovingbro/)
 * (@lovingbro)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/repetitive-database-query-affecting-performance/#post-18370453)
 * Hi [@upflowzajayden](https://wordpress.org/support/users/upflowzajayden/),
 * 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.
 *  [pmathbliss](https://wordpress.org/support/users/pmathbliss/)
 * (@pmathbliss)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/repetitive-database-query-affecting-performance/#post-18383745)
 * 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?
 * >     ```wp-block-code
   >     SELECTwp_posts.IDFROMwp_postsLEFT JOIN wp_term_relationshipsON (wp_posts.ID = wp_term_relationships.object_id)LEFT JOIN wp_postmetaON (wp_posts.ID = wp_postmeta.post_idAND wp_postmeta.meta_key = '_wc_gla_visibility')LEFT JOIN wp_postmeta AS mt1ON (wp_posts.ID = mt1.post_id)LEFT JOIN wp_postmeta AS mt2ON (wp_posts.ID = mt2.post_idAND mt2.meta_key = '_wc_gla_errors')LEFT JOIN wp_postmeta AS mt3ON (wp_posts.ID = mt3.post_id)LEFT JOIN wp_postmeta AS mt4ON (wp_posts.ID = mt4.post_id)LEFT JOIN wp_postmeta AS mt5ON (wp_posts.ID = mt5.post_idAND mt5.meta_key = '_wc_gla_visibility')LEFT JOIN wp_postmeta AS mt6ON (wp_posts.ID = mt6.post_id)LEFT JOIN wp_postmeta AS mt7ON (wp_posts.ID = mt7.post_idAND mt7.meta_key = '_wc_gla_errors')LEFT JOIN wp_postmeta AS mt8ON (wp_posts.ID = mt8.post_id)LEFT JOIN wp_postmeta AS mt9ON (wp_posts.ID = mt9.post_id)WHERE 1 = 1AND ((wp_term_relationships.term_taxonomy_id IN (2, 4)OR NOT EXISTS(SELECT1FROMwp_term_relationshipsINNER JOIN wp_term_taxonomyON wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_idWHERE wp_term_taxonomy.taxonomy = 'product_type'AND wp_term_relationships.object_id = wp_posts.ID)))AND ((wp_postmeta.post_id IS NULLOR (mt1.meta_key = '_wc_gla_visibility'AND mt1.meta_value != 'dont-sync-and-show'))AND (mt2.post_id IS NULLOR (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 NULLOR (mt6.meta_key = '_wc_gla_visibility'AND mt6.meta_value != 'dont-sync-and-show'))AND (mt7.post_id IS NULLOR (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.IDlimit 300, 100
   >     ```
   > 
 *     ```wp-block-code
       Here is my first pass, but it can be reduced farther. SELECT DISTINCTwp_posts.IDFROMwp_postsLEFT JOIN wp_term_relationshipsON (wp_posts.ID = wp_term_relationships.object_id)LEFT JOIN wp_postmeta mt1ON (wp_posts.ID = mt1.post_idAND mt1.meta_key = '_wc_gla_visibility')LEFT JOIN wp_postmeta AS mt2ON (wp_posts.ID = mt2.post_id)AND mt2.meta_key = '_wc_gla_errors'LEFT JOIN wp_postmeta AS mt3ON (wp_posts.ID = mt3.post_idAND mt3.meta_key = '_wc_gla_synced_at')WHERE 1 = 1AND 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(SELECT1FROMwp_term_relationshipsINNER JOIN wp_term_taxonomyON wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_idWHERE wp_term_taxonomy.taxonomy = 'product_type'AND wp_term_relationships.object_id = wp_posts.ID)))AND ((mt1.post_id IS NULLOR (IFNULL(mt1.meta_value,'') != 'dont-sync-and-show'))AND (mt2.post_id IS NULLOR (mt2.meta_value = ''))AND ((IFNULL(mt3.meta_value,'0') < '1740035105')))
       ```
   
 *  [pmathbliss](https://wordpress.org/support/users/pmathbliss/)
 * (@pmathbliss)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/repetitive-database-query-affecting-performance/#post-18383817)
 * 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.
 *     ```wp-block-code
       SELECT   wp_posts.IDFROM  wp_postsWHERE 1 = 1AND 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](https://wordpress.org/support/users/pmathbliss/).
      Reason: Add results of the query
 *  [Zee](https://wordpress.org/support/users/doublezed2/)
 * (@doublezed2)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/repetitive-database-query-affecting-performance/#post-18385362)
 * Hello [pmathbliss](https://wordpress.org/support/users/pmathbliss/),
 * 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.
 * Have a great day!
 *  Plugin Support [Feten L. a11n](https://wordpress.org/support/users/fetenlakhal/)
 * (@fetenlakhal)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/repetitive-database-query-affecting-performance/#post-18435531)
 * Hi there,
 * We’d also really appreciate a quick review if you have a moment: [https://wordpress.org/support/plugin/google-listings-and-ads/reviews/#new-post](https://wordpress.org/support/plugin/google-listings-and-ads/reviews/#new-post)

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Repetitive Database Query Affecting Performance’ is closed to new replies.

 * ![](https://ps.w.org/google-listings-and-ads/assets/icon.svg?rev=2775988)
 * [Google for WooCommerce](https://wordpress.org/plugins/google-listings-and-ads/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/google-listings-and-ads/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/google-listings-and-ads/)
 * [Active Topics](https://wordpress.org/support/plugin/google-listings-and-ads/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/google-listings-and-ads/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/google-listings-and-ads/reviews/)

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)

 * 11 replies
 * 5 participants
 * Last reply from: [Feten L. a11n](https://wordpress.org/support/users/fetenlakhal/)
 * Last activity: [1 year, 1 month ago](https://wordpress.org/support/topic/repetitive-database-query-affecting-performance/#post-18435531)
 * Status: resolved