admin管理员组

文章数量:1391766

Anyone know if there is likely a big performance difference to these two queries?

  1. get all posts by status = TRASH
  2. get all posts which have the meta key _delete_product and has a value of TRUE

I will be doing a nightly cron purge of all posts which are to be deleted. Best thing is to grab all relevant posts in the most efficient way possible here before looping through them.

Anyone know if there is likely a big performance difference to these two queries?

  1. get all posts by status = TRASH
  2. get all posts which have the meta key _delete_product and has a value of TRUE

I will be doing a nightly cron purge of all posts which are to be deleted. Best thing is to grab all relevant posts in the most efficient way possible here before looping through them.

Share Improve this question asked Feb 8, 2020 at 13:35 wharfdalewharfdale 3484 silver badges17 bronze badges 1
  • Using post_status means you don't need to do a JOIN to postmeta, so it's almost certainly considerably faster. – Jacob Peattie Commented Feb 8, 2020 at 14:19
Add a comment  | 

1 Answer 1

Reset to default 2

As mentioned in the comments, post_status is stored in the posts table but postmeta values are stores in postmeta table which is usually a much more heavy table than posts. Using a meta in db queries, results in adding a JOIN clause to the query to join this heavy table!

So using post_status is definitely a better performance choice.

本文标签: Look up all posts by status or meta valueperformance difference