Ecommerce Shopify WordPress Discussion

Same query different durations when coming from different source [closed]

Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 6 days ago. This post was edited and submitted for review 6 days ago. Improve this question SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (...) ORDER BY meta_id ASC; This query when executed by wordpress is taking 20+ seconds on the database itself, not end to end. It's showing in the slow query log. post_id is indexed. It should be quick. When running from MySQL Workbench I'm getting the result in fractions of a second. Not really sure why though. Tried doing optimize on the table. Tried removing the ORDER BY. $cache_key = $meta_type . '_meta'; $non_cached_ids = array(); $cache = array(); $cache_values = wp_cache_get_multiple( $object_ids, $cache_key ); foreach ( $cache_values as $id => $cached_object ) { if ( false === $cached_object ) { $non_cached_ids[] = $id; } else { $cache[ $id ] = $cached_object; } } if ( empty( $non_cached_ids ) ) { return $cache; } // Get meta info. $id_list = implode( ',', $non_cached_ids ); $id_column = ( 'user' === $meta_type ) ? 'umeta_id' : 'meta_id'; // This is the query generation in the wordpress meta.php file $meta_list = $wpdb->get_results( "SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list) ORDER BY $id_column ASC", ARRAY_A ); if ( ! empty( $meta_list ) ) { foreach ( $meta_list as $metarow ) { $mpid = (int) $metarow[ $column ]; $mkey = $metarow['meta_key']; $mval = $metarow['meta_value']; // Force subkeys to be array type. if ( ! isset( $cache[ $mpid ] ) || ! is_array( $cache[ $mpid ] ) ) { $cache[ $mpid ] = array(); } if ( ! isset( $cache[ $mpid ][ $mkey ] ) || ! is_array( $cache[ $mpid ][ $mkey ] ) ) { $cache[ $mpid ][ $mkey ] = array(); } // Add a value to the current pid/key. $cache[ $mpid ][ $mkey ][] = $mval; } } # Time: 2024-02-08T19:32:03.143347Z # User@Host: [XXXXXXXXX] @ [XXXXXXXXX] Id: 829199 # Query_time: 17.843975 Lock_time: 0.000097 Rows_sent: 155 Rows_examined: 19469798 SET timestamp=1707420705; SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (...) ORDER BY meta_id ASC; DB is Aurora MySQL Serverless v2 (16 - 48 ACUs) I can run the same query(with and without different values in the IN) in a 10th of a second from MySQL Workbench tunneled to the same DB at the same time these are taking the above duration(or longer) Check Table wp_postmeta; # Table, Op, Msg_type, Msg_text 'prod_wordpress.wp_postmeta', 'check', 'status', 'OK'
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.