admin管理员组文章数量:1277899
Ok, I hope I won't get downvoted for this being not a coding question, but I think this will benefit all who want to make their Wordpress projects more CPU efficient.
Basically on the other questions that I asked, I got a response that it's better to use Custom Taxonomy (same as category or tags), rather than using post meta data.
My question is, is it really better for server CPU and if yes, that means Custom Taxonomy is working completely different than Post meta data query?
I'm building a quite serious project and I want to make it as efficient as possible, so that I wouldn't need to redo all over again.
To clarify, is custom taxonomy more efficient than post meta data when it comes to querying the posts. Thanks.
Ok, I hope I won't get downvoted for this being not a coding question, but I think this will benefit all who want to make their Wordpress projects more CPU efficient.
Basically on the other questions that I asked, I got a response that it's better to use Custom Taxonomy (same as category or tags), rather than using post meta data.
My question is, is it really better for server CPU and if yes, that means Custom Taxonomy is working completely different than Post meta data query?
I'm building a quite serious project and I want to make it as efficient as possible, so that I wouldn't need to redo all over again.
To clarify, is custom taxonomy more efficient than post meta data when it comes to querying the posts. Thanks.
Share Improve this question asked Sep 28, 2021 at 10:24 robert0robert0 2032 silver badges11 bronze badges2 Answers
Reset to default 2Yes and no.
The post meta table is optimised for retrieving a posts keys/meta values when you already know the post ID. It is not optimised for searching and filtering.
The taxonomy tables are optimised for grouping and filtering, searching.
If you want to find all posts that have X, or Y, X and Y should be terms in a taxonomy.
If you know the data will be retrieved when you already know the post ID, use post meta. It is fast to retrieve meta belonging to a post. It is slow to do the reverse. The slowness also depends on your servers traffic as well as how much meta you've stored. As your site gets bigger and more popular, the cost rises quickly.
Other things to watch out for:
- avoid
not
or exclusions, they're extremely slow/heavy/expensive on the database, always ask the database for what you want, don't ask it to remove/exclude/hide things. Filter or X Y Z, don't filter out A B C, it's expensive/slow! If necessary, add extra data that says the opposite, e.g.show_on_homepage
instead ofhide_on_homepage
etc - avoid ordering by
RAND
, it is one of the worst things you can do for query performance - don't ask for more than 100 posts per page, you can always paginate or do multiple queries
- don't store everything as post meta, or everything ass terms/taxonomy, the point is they are good for different things, choose which for each piece of data you need to store.
- you can even store data in both, e.g. detailed data in post meta, and an approximation in a term for easy filtering. For example, storing
$5.96
in meta, and a$5-$10
term will avoid expensive query math and provide a trivial UI for users that's fast while still storing the exact price
- you can even store data in both, e.g. detailed data in post meta, and an approximation in a term for easy filtering. For example, storing
Yes, an SQL query that is for a single taxonomy will generally be faster than an SQL query that is for a post meta value. If you just need to check whether the post meta key exists, then that is performant. However, if you need to query for its value, that is a slower query. This is because by default there is no index on the meta_value in the postmeta table.
本文标签: post metaDoes using custom taxonomy is more CPU efficient than using metadata
版权声明:本文标题:post meta - Does using custom taxonomy is more CPU efficient than using meta_data? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741295588a2370799.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论