0

OUR RDS database is reading 100% CPU and over 100 connections. After investigation, we traced it to this query.

SELECT object_id, term_taxonomy_id FROM wp_term_relationships INNER JOIN wp_posts ON object_id = ID WHERE term_taxonomy_id IN (2,3,5,14,13,77,19,9,17,46,1,11,10758,10757,12,339,38,28,83,69,6835,42,29,35,16,15,30,30334,6,8775,72,4,22,18,87,306,300,110,130,81,33,97,60,11419,248,7827,8784,305,37,975,80,8,25318,1407,47,3114,33088,277,144,39,127,82,55,135,68,7,34,2937,73,235,96,67,79,118,121,53,95,32,58,116,51,59,65,56,52,70,64,66,10,28047,48,3665,530,63,145,10781,94,340,11092,50,1516,22719,91,71,204)

It is creating over 76 connections and causing the database to spike because of the high load time.

Upon investigation, we were able to trace the query to includes/taxanomy.php, in the _pad_term_counts() function

// Get the object and term ids and stick them in a lookup table.
    $tax_obj      = get_taxonomy( $taxonomy );
    $object_types = esc_sql( $tax_obj->object_type );
    $results      = $wpdb->get_results( "SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (" . implode( ',', array_keys( $term_ids ) ) . ") AND post_type IN ('" . implode( "', '", $object_types ) . "') AND post_status = 'publish'" );
    foreach ( $results as $row ) {
        $id                                   = $term_ids[ $row->term_taxonomy_id ];
        $term_items[ $id ][ $row->object_id ] = isset( $term_items[ $id ][ $row->object_id ] ) ? ++$term_items[ $id ][ $row->object_id ] : 1;
    }

We have searched our application and we didn't call any taxonomy. How can we solve or avoid this query?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.