我们正在写一个MMORPG假设我们有下表。 location_dynamic_objects
是要大量查询和更新的表。正如您所看到的,position_x
、position_y
、location_id
列以及对象类型都是重复的。但是,如果我们标准化并使用联接,我们将为所选数据应用额外的过滤器。我们计划将所有 location_static_objects
一次性发送给客户端,因此将它们与 location_dynamic_objects
放在一起没有任何实际意义。
静态对象表示要渲染的不可移动数据,并在位置加载时发送一次到客户端。动态对象代表经常更新的数据,如玩家、火箭、小行星等,并不断发送到客户端,选择取决于客户端的位置和位置。
我们的问题是我们是否应该放弃标准化以实现性能?
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
);
最佳答案
由于非规范化会增加数据的冗余,因此会增加总数据量。因此,非规范化很少能提高数据写入访问(创建和更新)的性能;通常情况恰恰相反。此外,即使对于读取查询,非规范化也会以一小组查询(通常只有一个)的性能提高为代价,换取访问非规范化数据的所有其他查询的性能下降。如果您为外键约束正确使用了人工主键,并在自然(主)键上辅以相应的唯一性约束,那么如果您看到通过非规范化获得了一点点性能提升,我会感到惊讶。
关于mysql - RDBMS 规范化与性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15857113/