这些数据库表的最佳设计是什么?
我需要找到最佳的解决方案,使数据库规范化并具有大量预期数据。
我的网站有一个标签表(包含关键字、id)以及与此标签表相关的 4 种类型的数据,例如(文章、资源、工作等)。
最大的问题是:- 对于与标签的关系,优化和优化的最佳解决方案是什么?查询速度?
为每个关系制作一个表格,例如:
- 表格articlesToTags(ArticleID,TagID)
- 表 jobsToTags(jobid,tagid)
- 等等
或者将其全部放在一个表中,例如
- 表标签关系(tagid、itemid、itemtype)
我需要你的帮助。请向我提供文章来帮助我进行此设计,
考虑到将来该网站可以添加与标签相关的新部分
谢谢
I need to find the best solution to make the DB Normalized with large amount of data expected.
My site has a Table Tags (contain key word,id) and also 4 types of data related to this tags table like(articles,resources,jobs,...).
The big question is:-
for the relation with tags what best solution for optimazaion & query speed?
make a table for each relation like:
- table articlesToTags(ArticleID,TagID)
- table jobsToTags(jobid,tagid)
- etc.
or put it all in one table like
- table tagsrelation(tagid,itemid,itemtype)
I need your help. Please provide me with articles to help me in this design
consider that in future the site can conation new section relate to tag
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会选择您的架构的规范化版本(即表关系)。这种类型的模式对于应用程序可能增长的场景非常有用。
将所有数据放在一个表中的坏处是,如果两种关系都有一堆属性,那么最终会得到一个包含大量属性的表,这些属性在增长时查询起来会很慢,从而变得您的应用程序的性能损失。
因此,最后的问题是在考虑可扩展性的情况下,针对设计良好的代码选择简单性和快速结束。
希望我能帮忙
I would go for the normalized version of your schema (which is the table-relation). This type of schemas are very useful for scenarios where the application might grow.
The bad thing of having all the data in just one table is that if you have a bunch of attributes for both relationships, you'll end up with a table with a lot of attributes, which when growing will be slow to query, thus becoming a performance hit of your app.
So, finally the problem is to choose simplicity and quick end against well designed code considering scalability as well.
Hope I can help