mysql - RDBMS 规范化与性能

标签 mysql sql performance normalization acid

我们正在写一个MMORPG假设我们有下表。 location_dynamic_objects 是要大量查询和更新的表。正如您所看到的,position_xposition_ylocation_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/

相关文章:

php - 我怎样才能缩短这个 MySQL 查询?

php - 如何在 php codeigniter 中只比较日期和年份

php - 我的 php/mysql 代码有什么问题?

mysql - 选择总值及其子集

php - 合并数组,将值相加

performance - Active Record Rails 中唯一性验证的效率

mysql - 使用适当的主键和索引对相对较小的表进行缓慢的 MySQL 查询

mysql - SQL CSV 跨表导入/导出发布数据

sql - 如何在 SQL Server 2008 R2 中强制一个列对于整个表是唯一的?

秒表和 foreach 循环的 C# *奇怪* 问题