admin管理员组文章数量:1194163
As we all know, a design pattern that is used frequently in WordPress' DB code is the idea of persisting data for a particular object (blog/post/comment), indexed with a particular name or key.
We see this pattern used in the following standard tables:
- wp_options
- wp_commentmeta
- wp_postmeta
As far as I can tell, the motivation for this design decision was to enable plugin/theme authors to persist data easily (e.g. by using custom fields) without having to modify the database schema. It would seem to me that there are few other advantages to this approach, since it is significantly slower and makes it harder to implement complex queries.
What are the other advantages to this approach, if any?
UPDATE: Reading info on the drawbacks of this approach:
- ://geekswithblogs/darrengosbell/archive/2006/03/12/kvpsindatabasedesign.aspx
As we all know, a design pattern that is used frequently in WordPress' DB code is the idea of persisting data for a particular object (blog/post/comment), indexed with a particular name or key.
We see this pattern used in the following standard tables:
- wp_options
- wp_commentmeta
- wp_postmeta
As far as I can tell, the motivation for this design decision was to enable plugin/theme authors to persist data easily (e.g. by using custom fields) without having to modify the database schema. It would seem to me that there are few other advantages to this approach, since it is significantly slower and makes it harder to implement complex queries.
What are the other advantages to this approach, if any?
UPDATE: Reading info on the drawbacks of this approach:
- https://stackoverflow.com/questions/126271/key-value-pairs-in-relational-database
- https://web.archive.org/web/20210119190408/http://geekswithblogs.net/darrengosbell/archive/2006/03/12/kvpsindatabasedesign.aspx
- I have no idea of database schemas or performance... But, just for the sake of the argument, can you reference your statements? Like in Wikipedia, "citation needed"... – brasofilo Commented Dec 21, 2012 at 2:20
- 1 Options are meant to be key-value pairs, there's nothing wrong there. However in the case of post meta, the answers you linked from stackoverflow are relevant here as well: this is just poor design. – onetrickpony Commented Dec 21, 2012 at 4:43
- Most important failure of WordPress is their database design. Its only useable for hosehold websites. High-performance sites will never use Anti-pattern as database design due to performance issues like BASIC indexing! – Victor Angelier Commented Jun 9, 2015 at 11:39
1 Answer
Reset to default 3The ability to store abstract key-value pairs without modifying the database structure is the reason. Without that, WordPress loses much of its flexibility. I can't speak for others, but the single largest reason why I develop atop WordPress is its flexible nature.
To quote one of your links above,
Usually the reasoning behind doing what you are doing is because the domains need to be "user definable". If that is the case then even I am not going to push you towards creating tables on the fly...
While it's true that it forces queries to be more complex, and a little slower, the benefits far outweigh the costs. But, hey, it's all about what you're doing. Don't use a hammer to bang in a screw. If you still want to use WordPress, but need to run complex queries on steady, structured sets of data, check out Pods.
I hope this helps you out!
本文标签: custom fieldWhat is the advantage of the wpoptions design pattern
版权声明:本文标题:custom field - What is the advantage of the wp_options design pattern? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738497999a2090098.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论