我需要一些想法如何处理我正在开发的网站的数据库结构,我已经绞尽脑汁有一段时间了,以找出设计表格以帮助其实现可扩展的最佳方法。以下是详细信息。
标准化方式类似于:
-- Listing_table (list_id, user_id, list_title , list_content, list_date)
-- Tags_table (tag_id, tag_type, tag_name, tag_slug)
-- Tags_Listing_table (list_id, tag_id)
-- Field_table (list_id, field_name, field_value)
这个结构可以吗?另外,有效查询所有这些信息的最佳方法是什么?我认为根本不可能在一次查询中获得所有这些信息。我有什么选择?
此外,每个列表将加载多个线程,并且这些线程内将包含多个帖子,所有帖子都在同一页面上,有点像:
[单页]
列表(标题、内容、标签、额外字段)
感谢所有提供帮助的人,我真的很感激你们所有人的见解。如果还有什么我可以添加来帮助您帮助我,请询问。我可以转储我的 SQL 结构。
I need some ideas how to handle the database structure for a site i'm working on, i have been whacking my brains over it for a while to figure out the best way to design the tables to help it become scalable. Here are the details.
-
Listing: A single post with title text, post date and simple other info. Will Connect with user table to get username.
-
Tags: Each listing can have several tags belonging to a 'type' Example:
Genre: Action, Supernatural, Comedy
Producers: Sunrise, Bones
-
Extra Fields: Each listing can have extra fields too Example:
Air Dates: 18th Dec 2010
Duration: 120 mins
The Normalized way would be something like:
-- Listing_table (list_id, user_id, list_title, list_content, list_date)
-- Tags_table (tag_id, tag_type, tag_name, tag_slug)
-- Tags_Listing_table (list_id, tag_id)
-- Field_table (list_id, field_name, field_value)
Would this structure be fine ? Also what would be the best way to query all this information efficiently. I don't think its possible at all to get all this in one query. what are my options?
Also each listing will load multiple threads and inside those threads will be multiple posts, all on the same page kinda like:
[SINGLE PAGE]
Listing (title, content, tags, extra fields)
Thanks for everyone who helps, I really would appreciate some insight you all. If there is anything further I can add to help you help me please ask. I can dump my SQL structure.
发布评论
评论(2)
无论您的目标是可扩展性还是性能,您几乎肯定会后悔这一点:
有关某些具体原因,请参阅 SQL 反模式反击。该结构从幻灯片 16 开始。另请阅读 Bad CaRMa,这与可扩展性和性能有关。
Whether you're aiming for scalability or performance, you'll almost certainly regret this:
For some of the specific reasons, see SQL Antipatterns Strike Back. This structure starts on slide 16. Also read Bad CaRMa, which has to do with both scalability and performance.
这看起来像是典型的实体属性值方法。这个模型很好,特别是对于高流量网站,但它不太适合 SQL。而不是:
您会发现自己编写的查询如下:
这只是为了简单的日期比较。这变得非常非常复杂。
基本上,EAV 是一种权衡,您将数据库主要用于持久存储,较少用于逻辑和报告生成。
This looks like a typical entity-attribute-value approach. This model is fine, especially for high traffic websites, but it does not lend itself well to SQL. Instead of:
You'll find yourself writing queries like:
And that's just for a simple date compare. This gets complex really really fast.
Basically, EAV is a tradeoff where you use the database mostly for persistant storage and less for logic and report generation.