2013-04-06 58 views
0

我们正在编写MMORPG并假设我们有以下表格。 location_dynamic_objects是要查询和更新HEAVILY的表格。正如你可以看到position_xposition_ylocation_id列以及对象类型重复。但是,如果我们规范化并使用连接,我们将为选定的数据应用额外的过滤器。我们计划将所有location_static_objects一次性发送给客户,因此将它们与location_dynamic_objects保持在一起并没有真正的意义。 静态对象表示要呈现的不可移动数据,并在位置加载时向客户端发送一次。动态对象代表频繁更新的数据,如玩家,火箭,小行星等,并不断发送给客户端,取决于客户的位置和位置。 我们的问题是我们应该放弃规范化来实现绩效?RDBMS规范化与性能

create table location_static_object_types (
    location_static_object_type_id integer auto_increment primary key, 
    object_type_name    varchar(16) not null 
); 
create table location_static_objects (
    location_static_object_id  integer auto_increment primary key, 
    location_static_object_type_id integer not null, 
    location_id     integer not null, 
    position_x      integer not null, 
    position_y      integer not null 
); 
create table location_dynamic_object_types (
    location_dynamic_object_type_id integer auto_increment primary key, 
    object_type_name    varchar(16) not null 
); 
create table location_dynamic_objects (
    location_dynamic_object_id  integer auto_increment primary key, 
    location_dynamic_object_type_id integer not null, 
    object_native_id    integer not null, 
    location_id      integer not null, 
    position_x      integer not null, 
    position_y      integer not null 
); 
+1

我不确定仅仅因为可能会有一两个连接,你的表现将被毁坏。通过适当的索引,调整,也许还有一些应用程序缓存,事情可能会像你需要的那样快。 – mconlin 2013-04-06 23:27:44

+1

只有在您经过全面测试并且有证据表明您需要恢复正常表单时,才应该进行标准化。 – Kermit 2013-04-06 23:30:27

+0

即使我们添加索引,我们也需要过滤对象类型,重点是将未过滤的数据发送给客户端。 – OneMoreVladimir 2013-04-06 23:39:58

回答

2

由于非规格化会增加数据的冗余度,因此会增加总数据量。出于这个原因,非规范化对于提高写入访问(创建和更新)数据的性能是非常罕见的;反之亦然。此外,即使对于读取查询,反规范化也会影响一小组查询的性能提高,通常只有一组查询会降低所有其他访问非规范化数据的性能。如果你已经为你的外键约束适当地使用了人造主键,并在你的自然键(主键)上补充了相应的唯一性约束,如果你通过非规范化看到了性能增益的好处,我会感到惊讶。

+0

我确实同意你的观点。但我不喜欢“恰当的标准化”涉及使用人造主键的含义。这两件事没有任何关系。 – 2013-04-07 10:41:08

+0

我的关于人造主键的短语实际上是“正确使用”,这对性能有影响。 – 2013-04-07 11:51:38