我正在尝试制作一些分类广告网站。我找到了一些开源分类项目:osclass。
所以我将参考osclass设计数据库结构。 osclass的数据库结构设计如下:
类别项数据表已分为7个小数据表,如:
oc_t_item: Stores some base item information.
oc_t_item_comment: Stores the comment for item.
oc_t_item_description: Stores title, content for the item.
oc_t_item_location: Store the location information for the item.
oc_t_item_meta: Store some extra meta information for the item.
oc_t_item_resource: Store the image resources information for the item.
但我不认为这会是明智的运动虽然它使逻辑和结构清晰。如果我们想要检索某些类别项的某些信息,我们必须在这些数据表之间进行这么多连接操作,这会导致很大的性能损失。那么,将一些大型数据表拆分成一些小数据表的基本原则和最佳实践是什么?
答案 0 :(得分:1)
您不应该仅仅因为对join
的关注而拆分这样的表。如果相关的表使用FK的主键或具有正确列的索引,则数据检索将非常有效。有关如何使用查询分析来确保查询使用正确的索引,引用等的示例,请参阅this post and the comments+answers。
另外,如果你要分割表格来移动表格中的location
(一个varchar字段?),那么你的字段是否是固定宽度的?如果没有,如果表格中还有其他可变宽度列,例如item_name
,则移出一个可变宽度列所获得的数据检索速度优势将会丢失。
(另请注意,see this answer关于ppl考虑对提高性能所做的优化类型。)