我正在尝试确定存储具有非常相似属性的实体的最佳方式。主要区别在于每个实体都引用其他实体。我打算将数据库设置为:
entity_a (1-1,000 Records) [Data rarely changes]
id|created|updated|entity_b_id|category_id|name|entity_b_id|entity_c_id|entity_d_id
entity_b (10,000-1,000,000 Records) [Data changes constantly]
id|created|updated|entity_b_id|category_id|name|entity_c_id|entity_e_id|entity_f_id
entity_c (10,000-10,000,000 Records) [Data changes constantly]
id|created|updated|entity_b_id|category_id|name|entity_a_id|entity_f_id
entity_d (0-1,000 Records) [Data rarely changes]
id|created|updated|entity_b_id|category_id|name
entity_e (1-100 Records) [Data rarely changes]
id|created|updated|entity_b_id|category_id|name|entity_a_id|entity_b_id
entity_f (0-50,000 Records) [Data frequently changes]
id|created|updated|entity_b_id|category_id|name|entity_c
entity_g (10-100 Records) [Data rarely changes]
id|created|updated|entity_b_id|category_id|name
entity_h (10-1,000 Records) [Data rarely changes]
id|created|updated|entity_b_id|category_id|name|entity_e_id
entity_i (1-10 Records) [Data rarely changes]
id|created|updated|entity_b_id|category_id|name
但有人建议管理一张大表会更容易:
ent (20,000-11,000,000 Records)
id|created|updated|ent_id(b)|category_id|name|ent_id(a)|ent_id(b)|ent_id(c)|ent_id(d)|ent_id(e)|ent_id(f)
第二种方法的一个问题是表大小,因为 id 将是 int(11),并且这些 id 将有六列,主要设置为 0。
但我主要关心的是访问速度,因为许多用户一次会非常频繁地访问记录。我正在使用 CodeIgniter 并希望使用它的缓存功能来尽可能多地承受数据库的负载,但这会受到限制,因为某些数据会每秒发生变化。
非常感激任何的帮助。