Title: [Plugin: Posts 2 Posts] Unnecessarily slow query?
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Unnecessarily slow query?

 *  [Mitsugari Yamamoto](https://wordpress.org/support/users/mityama/)
 * (@mityama)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-unnecessarily-slow-query/)
 * Hi scribu!
 * My site in development has become quite slow in certain situations in which I
   use P2P. I have analyzed site performance with the WordPress debug bar and found
   some very slow queries which take ~2.5 seconds each. The slowness is caused by
   an inner query, which seems unnecessary, because the post ID it’s querying for
   is already known:
 * SELECT wp_2_posts.*, wp_2_p2p.* FROM wp_2_posts INNER JOIN wp_2_p2p WHERE 1=1
   AND wp_2_posts.post_type IN (‘company’) AND (wp_2_posts.post_status = ‘publish’)
   AND (wp_2_p2p.p2p_type = ‘company’ AND wp_2_posts.ID = wp_2_p2p.p2p_to AND wp_2_p2p.
   p2p_from IN (SELECT wp_2_posts.ID FROM wp_2_posts WHERE 1=1 AND wp_2_posts.ID
   IN (175853) AND wp_2_posts.post_type IN (‘game’) AND (wp_2_posts.post_status 
   = ‘publish’ OR wp_2_posts.post_status = ‘private’) ORDER BY wp_2_posts.post_date
   DESC )) ORDER BY wp_2_posts.post_date DESC
 * Replacing the inner query with just the post ID brings the execution time down
   to only 0.007 seconds! Is this a bug?
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-unnecessarily-slow-query/#post-3070851)
 * Replacing the inner query with the post ID sidesteps some important checks, for
   example if the post is an auto-draft:
 * [http://wordpress.org/support/topic/plugin-posts-2-posts-auto-draft-posts-break-one-to-one-connections?replies=8](http://wordpress.org/support/topic/plugin-posts-2-posts-auto-draft-posts-break-one-to-one-connections?replies=8)
 * Some actual solutions to the slow query are discussed here:
 * [https://github.com/scribu/wp-posts-to-posts/issues/219](https://github.com/scribu/wp-posts-to-posts/issues/219)
 *  Thread Starter [Mitsugari Yamamoto](https://wordpress.org/support/users/mityama/)
 * (@mityama)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-unnecessarily-slow-query/#post-3070872)
 * I see, did not think about those darn Auto-Drafts. I am glad the issue is already
   being worked on. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘[Plugin: Posts 2 Posts] Unnecessarily slow query?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/posts-to-posts_7a8e9d.svg)
 * [Posts 2 Posts](https://wordpress.org/plugins/posts-to-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/posts-to-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/posts-to-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/posts-to-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/posts-to-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/posts-to-posts/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Mitsugari Yamamoto](https://wordpress.org/support/users/mityama/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-unnecessarily-slow-query/#post-3070872)
 * Status: not resolved