Title: large database queries
Last modified: April 14, 2026

---

# large database queries

 *  Resolved [frnzsk](https://wordpress.org/support/users/frnzsk/)
 * (@frnzsk)
 * [1 month, 2 weeks ago](https://wordpress.org/support/topic/large-database-queries/)
 * Hello,
 * From our Hosting we are informed that the “Price Based Country” plugin is generating
   extremely large queries that do not finish and cause overload on the servers.
   Can you tell us how to solve it?
 * An example would be this query that reviews 37 million rows:
 *     ```wp-block-code
       # User@Host: xxxxx[xxxxx] @ localhost [] Thread_id: 4 Schema: xxxxx QC_hit: No Query_time: 162103.893545 Lock_time: 0.003978 Rows_sent: 0 Rows_examined: 37436284189 Rows_affected: 0 Bytes_sent: 0SET timestamp=1775896851;SELECT zones_query.zone_id, posts.ID as post_idFROM wp_posts postsCROSS JOIN ((SELECT 'zona-euro' as zone_id, convert('_zona-euro_price_method' using utf8) AS '_price_method_field_name', convert('_zona-euro_sale_price_dates' using utf8) AS '_sale_price_dates_field_name', convert('_zona-euro_price' using utf8) AS '_price_field_name', convert('_zona-euro_sale_price' using utf8) AS '_sale_price_field_name', convert('_zona-euro_sale_price_dates_from' using utf8) AS '_sale_price_dates_from_field_name', convert('_zona-euro_sale_price_dates_to' using utf8) AS '_sale_price_dates_to_field_name', ('1'+0) AS exchange_rate ) UNION (SELECT 'zona-no-euro-y-europa-no-ue' as zone_id, convert('_zona-no-euro-y-europa-no-ue_price_method' using utf8) AS '_price_method_field_name', convert('_zona-no-euro-y-europa-no-ue_sale_price_dates' using utf8) AS '_sale_price_dates_field_name', convert('_zona-no-euro-y-europa-no-ue_price' using utf8) AS '_price_field_name', convert('_zona-no-euro-y-europa-no-ue_sale_price' using utf8) AS '_sale_price_field_name', convert('_zona-no-euro-y-europa-no-ue_sale_price_dates_from' using utf8) AS '_sale_price_dates_from_field_name', convert('_zona-no-euro-y-europa-no-ue_sale_price_dates_to' using utf8) AS '_sale_price_dates_to_field_name', ('1'+0) AS exchange_rate ) UNION (SELECT 'usa-y-canada' as zone_id, convert('_usa-y-canada_price_method' using utf8) AS '_price_method_field_name', convert('_usa-y-canada_sale_price_dates' using utf8) AS '_sale_price_dates_field_name', convert('_usa-y-canada_price' using utf8) AS '_price_field_name', convert('_usa-y-canada_sale_price' using utf8) AS '_sale_price_field_name', convert('_usa-y-canada_sale_price_dates_from' using utf8) AS '_sale_price_dates_from_field_name', convert('_usa-y-canada_sale_price_dates_to' using utf8) AS '_sale_price_dates_to_field_name', ('1'+0) AS exchange_rate ) UNION (SELECT 'latam' as zone_id, convert('_latam_price_method' using utf8) AS '_price_method_field_name', convert('_latam_sale_price_dates' using utf8) AS '_sale_price_dates_field_name', convert('_latam_price' using utf8) AS '_price_field_name', convert('_latam_sale_price' using utf8) AS '_sale_price_field_name', convert('_latam_sale_price_dates_from' using utf8) AS '_sale_price_dates_from_field_name', convert('_latam_sale_price_dates_to' using utf8) AS '_sale_price_dates_to_field_name', ('1'+0) AS exchange_rate ) UNION (SELECT 'asia' as zone_id, convert('_asia_price_method' using utf8) AS '_price_method_field_name', convert('_asia_sale_price_dates' using utf8) AS '_sale_price_dates_field_name', convert('_asia_price' using utf8) AS '_price_field_name', convert('_asia_sale_price' using utf8) AS '_sale_price_field_name', convert('_asia_sale_price_dates_from' using utf8) AS '_sale_price_dates_from_field_name', convert('_asia_sale_price_dates_to' using utf8) AS '_sale_price_dates_to_field_name', ('1'+0) AS exchange_rate ) UNION (SELECT 'mena' as zone_id, convert('_mena_price_method' using utf8) AS '_price_method_field_name', convert('_mena_sale_price_dates' using utf8) AS '_sale_price_dates_field_name', convert('_mena_price' using utf8) AS '_price_field_name', convert('_mena_sale_price' using utf8) AS '_sale_price_field_name', convert('_mena_sale_price_dates_from' using utf8) AS '_sale_price_dates_from_field_name', convert('_mena_sale_price_dates_to' using utf8) AS '_sale_price_dates_to_field_name', ('1'+0) AS exchange_rate ) UNION (SELECT 'africa-sub-sahariana' as zone_id, convert('_africa-sub-sahariana_price_method' using utf8) AS '_price_method_field_name', convert('_africa-sub-sahariana_sale_price_dates' using utf8) AS '_sale_price_dates_field_name', convert('_africa-sub-sahariana_price' using utf8) AS '_price_field_name', convert('_africa-sub-sahariana_sale_price' using utf8) AS '_sale_price_field_name', convert('_africa-sub-sahariana_sale_price_dates_from' using utf8) AS '_sale_price_dates_from_field_name', convert('_africa-sub-sahariana_sale_price_dates_to' using utf8) AS '_sale_price_dates_to_field_name', ('1'+0) AS exchange_rate ) UNION (SELECT 'oceania' as zone_id, convert('_oceania_price_method' using utf8) AS '_price_method_field_name', convert('_oceania_sale_price_dates' using utf8) AS '_sale_price_dates_field_name', convert('_oceania_price' using utf8) AS '_price_field_name', convert('_oceania_sale_price' using utf8) AS '_sale_price_field_name', convert('_oceania_sale_price_dates_from' using utf8) AS '_sale_price_dates_from_field_name', convert('_oceania_sale_price_dates_to' using utf8) AS '_sale_price_dates_to_field_name', ('1'+0) AS exchange_rate )) as zones_queryINNER JOIN wp_postmeta meta__price_methodON meta__price_method.post_id = posts.IDAND meta__price_method.meta_key = zones_query._price_method_field_nameINNER JOIN wp_postmeta meta__sale_price_datesON meta__sale_price_dates.post_id = posts.IDAND meta__sale_price_dates.meta_key = zones_query._sale_price_dates_field_nameINNER JOIN wp_postmeta meta__sale_price_dates_fromON meta__sale_price_dates_from.post_id = posts.IDAND meta__sale_price_dates_from.meta_key = zones_query._sale_price_dates_from_field_nameINNER JOIN wp_postmeta meta__sale_price_dates_toON meta__sale_price_dates_to.post_id = posts.IDAND meta__sale_price_dates_to.meta_key = zones_query._sale_price_dates_to_field_nameINNER JOIN wp_postmeta meta__sale_priceON meta__sale_price.post_id = posts.IDAND meta__sale_price.meta_key = zones_query._sale_price_field_nameINNER JOIN wp_postmeta meta__priceON meta__price.post_id = posts.IDAND meta__price.meta_key = zones_query._price_field_nameWHERE posts.post_type IN ('product', 'product_variation') AND posts.post_status NOT IN ('trash', 'auto-draft')AND meta__price_method.meta_value = 'manual'AND meta__sale_price_dates.meta_value = 'manual'AND meta__sale_price.meta_value != ''AND meta__price.meta_value != meta__sale_price.meta_value                                    AND meta__sale_price_dates_from.meta_value < '1775845852'                                    AND meta__sale_price_dates_from.meta_value > 0                                    AND ( meta__sale_price_dates_to.meta_value > '1775845852' OR meta__sale_price_dates_to.meta_value + 0 = 0 )                                    ORDER BY zones_query.zone_id, posts.ID;#
       ```
   
 * I just enabled the “Load product prices in the background” option. Can this help?
 * Greetings and thanks

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

 *  Plugin Author [Oscar Gare](https://wordpress.org/support/users/oscargare/)
 * (@oscargare)
 * [1 month, 2 weeks ago](https://wordpress.org/support/topic/large-database-queries/#post-18880054)
 * Hi there,
 * This query retrieves the products for which the scheduled sale price starts or
   ends. It runs every day on the `woocommerce_scheduled_sales` hook. The query 
   is affecting you runs to get the products that have the “scheduled sale price
   date” set to “manual” for the pricing zones.
 * How many products and how many pricing zones do you have? 37 million rows are
   a lot of rows.
   If you don’t have products that have the “scheduled sale price
   date” set to “manual” for the pricing zones, you can turn off this daily task
   with the following code snippet:
 *     ```wp-block-code
       remove_action( 'woocommerce_scheduled_sales', [ 'WCPBC_Product_Meta_Data', 'scheduled_sales' ], 11 );
       ```
   
 *  Thread Starter [frnzsk](https://wordpress.org/support/users/frnzsk/)
 * (@frnzsk)
 * [1 month, 2 weeks ago](https://wordpress.org/support/topic/large-database-queries/#post-18880230)
 * Thank you very much for your response.
 * My store has 238 products, in 2 languages (polylang), and 8 pricing zones.
 * I currently don’t have any discounts so I’m going to implement the snippet you
   recommended as a temporary measure, but can you think of a solution without giving
   up the discounts?
 * Greetings and thanks
 *  Plugin Author [Oscar Gare](https://wordpress.org/support/users/oscargare/)
 * (@oscargare)
 * [1 month, 2 weeks ago](https://wordpress.org/support/topic/large-database-queries/#post-18882456)
 * Hi,
   We’re working on improving the process that runs this query. These improvements
   will be included in the next plugin version.
 *  Plugin Author [Oscar Gare](https://wordpress.org/support/users/oscargare/)
 * (@oscargare)
 * [3 weeks, 2 days ago](https://wordpress.org/support/topic/large-database-queries/#post-18901942)
 * Hi,
   Version 4.3 solves the issue with this query. Please update.

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

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Flarge-database-queries%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/woocommerce-product-price-based-on-countries/assets/icon-
   256x256.png?rev=1976858)
 * [Price Based on Country for WooCommerce](https://wordpress.org/plugins/woocommerce-product-price-based-on-countries/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-product-price-based-on-countries/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-product-price-based-on-countries/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-product-price-based-on-countries/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-product-price-based-on-countries/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-product-price-based-on-countries/reviews/)

## Tags

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

 * 4 replies
 * 2 participants
 * Last reply from: [Oscar Gare](https://wordpress.org/support/users/oscargare/)
 * Last activity: [3 weeks, 2 days ago](https://wordpress.org/support/topic/large-database-queries/#post-18901942)
 * Status: resolved