• Resolved Albert

    (@planetshaker)


    I’m about to get crazy over this. Not sure when exactly it started, but since about 4 weeks, every single morning, a long running SQL query crashes our site. I’ve even installed a monitor to see that: https://monitor.heukelbach.org/

    The website goes down at around 6am every day for about 40 minutes, then recovers, goes down again for about 10 minutes and then it’s fine for the rest of the day.

    It’s so heavy that I even cannot login into anything, including PHPMyAdmin. WordPress says “Error establishing database connection”.

    Now comes the interesting part: I got the chance to catch the query a few times. It always looks like this, and it’s clearly something about WooCommerce:

    SELECT O8WHc_2_posts.* FROM O8WHc_2_posts LEFT JOIN O8WHc_2_postmeta AS mt1 ON ( O8WHc_2_posts.post_parent = mt1.post_id AND mt1.meta_key = '_shipping_country' ) OR ( O8WHc_2_posts.ID = mt1.post_id AND mt1.meta_key = '_shipping_country' ) LEFT JOIN O8WHc_2_postmeta AS mt2 ON ( O8WHc_2_posts.post_parent = mt2.post_id AND mt2.meta_key = '_billing_country' ) OR ( O8WHc_2_posts.ID = mt2.post_id AND mt2.meta_key = '_billing_country' ) LEFT JOIN O8WHc_2_postmeta AS mt3 ON ( O8WHc_2_posts.ID = mt3.post_id AND mt3.meta_key = '_date_paid' ) WHERE 1=1 AND ( NOT mt3.post_id IS NULL AND ( mt3.meta_key = '_date_paid' AND mt3.meta_value >= '1628121600' AND mt3.meta_value <= '1628121600' ) OR O8WHc_2_posts.post_parent > 0 AND ( O8WHc_2_posts.post_date >= '2021-08-05' AND O8WHc_2_posts.post_date <= '2021-08-05' ) ) AND ( ( mt1.post_id IS NULL AND ( mt2.meta_key = '_billing_country' AND mt2.meta_value IN ('AT','BE','BG','CY','CZ','DK','EE','ES','FI','FR','GR','HR','HU','IE','IT','LT','LU','LV','MT','NL','PL','PT','RO','SE','SI','SK','MC','GB') ) ) OR ( mt1.meta_key = '_shipping_country' AND mt1.meta_value IN ('AT','BE','BG','CY','CZ','DK','EE','ES','FI','FR','GR','HR','HU','IE','IT','LT','LU','LV','MT','NL','PL','PT','RO','SE','SI','SK','MC','GB') ) ) AND (O8WHc_2_posts.post_type IN ('shop_order')) AND (O8WHc_2_posts.post_status IN ('wc-processing','wc-on-hold','wc-completed')) GROUP BY O8WHc_2_posts.ID ORDER BY O8WHc_2_posts.post_date ASC LIMIT 0, 2

    Now I found the origin of this query in

    /woocommerce-germanized/packages/one-stop-shop-woocommerce/src/Queue.php

    Line 141:

    public static function build_query( $args ) {
    		global $wpdb;
    
    		$joins = array(
    			"LEFT JOIN {$wpdb->postmeta} AS mt1 ON ( {$wpdb->posts}.post_parent = mt1.post_id AND mt1.meta_key = '_shipping_country' ) OR ( {$wpdb->posts}.ID = mt1.post_id AND mt1.meta_key = '_shipping_country' )",
    			"LEFT JOIN {$wpdb->postmeta} AS mt2 ON ( {$wpdb->posts}.post_parent = mt2.post_id AND mt2.meta_key = '_billing_country' ) OR ( {$wpdb->posts}.ID = mt2.post_id AND mt2.meta_key = '_billing_country' )"
    		);

    Can you please help solving this problem?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author vendidero

    (@vendidero)

    Hi Albert,

    this query is part of the OSS threshold observer. You might adjust (and disable) it via WooCommerce > Settings > Germanized > OSS. The query is actually not that special and it uses a limit to make sure that the query does not ask for too much data. Did you manually try to execute the query, e.g. via PHPmyadmin? I was not yet able to find any problems with that query but have heard from other customers that it might be problematic in certain hosting environments. How many posts/orders are managed within your wp_posts table?

    Cheers

    Thread Starter Albert

    (@planetshaker)

    Hi, yes, the only way to get around this server-crashing issue is to disable it completely for us.

    I also tried to run it manually – and it started the neverending process, running for more than 5000 seconds.

    We had orders since 2016, and now have 42.000 orders in there. We already deleted 50.000 orders from 2016-2019, but those we need to keep.

    Since I’ve deactivated it, the server is running well. So the query needs some improvement, I guess….

    Plugin Author vendidero

    (@vendidero)

    Hi there,

    the problem is that I was not yet able to reproduce the issue. How many entries do you have within your wp_posts and wp_postmeta table? Do you offer mainly digital products?

    Cheers

    Plugin Author vendidero

    (@vendidero)

    Hi @planetshaker,

    we are currently working on improving the query. Could you please reach out to us at [email protected] so that we can test an alternate query together? That would be really nice ??

    Cheers

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Germanized creates loong running query, crashes website every day’ is closed to new replies.