【问题标题】:How to split a large data table to some small data tables?如何将一个大数据表拆分成一些小数据表?
【发布时间】:2013-08-06 19:40:11
【问题描述】:

我正在尝试制作一些分类广告网站。我发现了一些开源分类项目: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.

但我认为这不是明智的举动,尽管它使逻辑和结构清晰。如果我们想检索一些关于某个类别项目的信息,我们必须在这些数据表之间做很多连接操作,这会导致很大的性能损失。那么,将一些大数据表拆分成一些小数据表的基本原则和最佳实践是什么?

【问题讨论】:

  • 所有这些表都有相同的主键吗?
  • oc_t_item 定义了主键,即 item_id。其他人将此主键作为外键。

标签: database database-design database-performance


【解决方案1】:

您不应该仅仅出于对joins 的关注而需要拆分表格。如果相关表使用 FK 的主键或具有正确列的索引,则数据检索将非常有效。请参阅this post and the comments+answers,了解如何使用查询分析来确保您的查询使用正确的索引、引用等。

另外,如果您要拆分表格以将 location(varchar 字段?)之类的内容移出表格,那么您留下的字段是否具有固定宽度?否则,如果表中仍保留其他可变宽度列,例如item_name,则移出一个可变宽度列所获得的数据检索速度优势将丢失。

(附带说明,see this answer 关于人们考虑为提高性能所做的优化类型。)

【讨论】:

    猜你喜欢
    • 2011-06-20
    • 2021-03-12
    • 2016-04-12
    • 2013-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多