• Resolved rahulattrey

    (@rahulattrey)


    Hi Team,
    
    We couldn't determine the source of the query below. Could you provide suggestions on how we can identify and optimize the mentioned query?
    
    Query#1: Time: 2023-11-28T18:27:14.108304+05:30 User@Host: itgd_VS_write[itgd_VS_write] @ ip-10-6-100-149.ap-south-1.compute.internal [10.6.100.149] Id: 4548821 Query_time: 1.070314 Lock_time: 0.000168 Rows_sent: 50 Rows_examined: 514055
    
    SET timestamp=1701176233;
    SELECT SQL_CALC_FOUND_ROWS wp_2_posts.ID
    FROM wp_2_posts
    WHERE 1=1 AND (
    (
    wp_2_posts.ID NOT IN (
    SELECT object_id
    FROM wp_2_term_relationships
    WHERE term_taxonomy_id IN (16,3,7,5)
    )
    )
    ) AND (wp_2_posts.post_mime_type = 'image/webp' OR wp_2_posts.post_mime_type = 'image/png' OR wp_2_posts.post_mime_type = 'image/jpeg' OR wp_2_posts.post_mime_type = 'image/gif' OR wp_2_posts.post_mime_type = 'video/mp4' OR wp_2_posts.post_mime_type = 'video/webm') AND wp_2_posts.post_type = 'attachment' AND ((wp_2_posts.post_status = 'inherit'))
    GROUP BY wp_2_posts.ID
    ORDER BY wp_2_posts.post_date DESC
    LIMIT 0, 50;
    
    Query #2: Time: 2023-11-28T18:27:15.289480+05:30 User@Host: itgd_VS_write[itgd_VS_write] @ ip-10-6-100-149.ap-south-1.compute.internal [10.6.100.149] Id: 4548821 Query_time: 1.050797 Lock_time: 0.000264 Rows_sent: 10 Rows_examined: 514055
    
    SET timestamp=1701176234;
    SELECT SQL_CALC_FOUND_ROWS wp_2_posts.ID
    FROM wp_2_posts
    WHERE 1=1 AND (
    (
    wp_2_posts.ID NOT IN (
    SELECT object_id
    FROM wp_2_term_relationships
    WHERE term_taxonomy_id IN (16,3,7,5)
    )
    )
    ) AND (wp_2_posts.post_mime_type = 'image/webp' OR wp_2_posts.post_mime_type = 'image/png' OR wp_2_posts.post_mime_type = 'image/jpeg' OR wp_2_posts.post_mime_type = 'image/gif' OR wp_2_posts.post_mime_type = 'video/mp4' OR wp_2_posts.post_mime_type = 'video/webm') AND wp_2_posts.post_type = 'attachment' AND ((wp_2_posts.post_status = 'inherit'))
    GROUP BY wp_2_posts.ID
    ORDER BY wp_2_posts.post_date DESC
    LIMIT 0, 10;
    
    Query#3: Time: 2023-11-28T18:30:05.543965+05:30 User@Host: itgd_VS_write[itgd_VS_write] @ ip-10-6-101-212.ap-south-1.compute.internal [10.6.101.212] Id: 4553148 Query_time: 1.188332 Lock_time: 0.000156 Rows_sent: 25 Rows_examined: 514055
    
    SET timestamp=1701176404;
    SELECT SQL_CALC_FOUND_ROWS wp_2_posts.ID
    FROM wp_2_posts
    WHERE 1=1 AND (
    (
    wp_2_posts.ID NOT IN (
    SELECT object_id
    FROM wp_2_term_relationships
    WHERE term_taxonomy_id IN (16,3,7,5)
    )
    )
    ) AND (wp_2_posts.post_mime_type = 'image/webp' OR wp_2_posts.post_mime_type = 'image/png' OR wp_2_posts.post_mime_type = 'image/jpeg' OR wp_2_posts.post_mime_type = 'image/gif' OR wp_2_posts.post_mime_type = 'video/mp4' OR wp_2_posts.post_mime_type = 'video/webm') AND wp_2_posts.post_type = 'attachment' AND ((wp_2_posts.post_status = 'inherit'))
    GROUP BY wp_2_posts.ID
    ORDER BY wp_2_posts.post_date DESC
    LIMIT 0, 25;

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Pascal Birchler

    (@swissspidy)

    This looks like the default query initiated by WP_REST_Attachments_Controller to return media elements for showing in the story editor’s media library. Query time doesn’t seem particularly slow. With a large posts table and many media items, such queries are definitely possible.

    To improve query times I’d suggest updating to the latest WordPress version and considering using an external object cache (like Redis or Memcached) so that found post objects can be cached by WordPress.

    If you have further, general questions about WP_Query optimizations, I’d recommend asking in the general support forums.

Viewing 1 replies (of 1 total)
  • The topic ‘Optimize Query’ is closed to new replies.