Custom Podcast Feed INNER JOIN Causes Large Volume of Temporary Tables
-
We noticed that the following query repeatedly causes a high volume of temporary tables in our MySQL server environment:
(Reference: Line 2126 of powerpress.php latest version)
if( powerpress_is_custom_podcast_feed() || get_query_var('feed') === 'podcast' ) { global $wpdb; $join .= " INNER JOIN {$wpdb->postmeta} AS pp_{$wpdb->postmeta} "; $join .= " ON {$wpdb->posts}.ID = pp_{$wpdb->postmeta}.post_id "; }
The query is generated as:
SELECT
wp_posts
. * FROMwp_posts
INNER JOINwp_postmeta
ASpp_wp_postmeta
ONwp_posts
.ID
=pp_wp_postmeta
.post_id
WHERE ? = ? ANDwp_posts
.post_name
= ? ANDwp_posts
.post_type
= ? AND (pp_wp_postmeta
.meta_key
= ? ) GROUP BYwp_posts
.ID
ORDER BYwp_posts
.post_date
DESCIf I am reading it correctly, the root cause appears to be that MySQL is generating a temporary table to handle the sort:
SELECT
wp_posts
. * FROMwp ...
wp_posts.
post_date` DESCWe’ve added an index on the post_date field in wp_posts to try and mitigate the full row scan via temp table.
Do you have any recommendations or improvements that can be made to this plugin’s query to prevent the operation from creating a high volume of temporary tables on disk?
Statistics: Of the half dozen or so customers that use this plugin regularly on this hosting node, we observe about 13k temporary tables per hour generated by this query.
- The topic ‘Custom Podcast Feed INNER JOIN Causes Large Volume of Temporary Tables’ is closed to new replies.