【发布时间】:2013-03-29 05:41:24
【问题描述】:
我们正在编写MMORPG 并假设我们有以下表格。 location_dynamic_objects 是要大量查询和更新的表。如您所见,position_x、position_y、location_id 列以及对象类型都是重复的。但是,如果我们规范化并使用连接,我们将为选定的数据应用额外的过滤器。我们计划将所有location_static_objects ONCE 发送给客户,因此将它们与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
);
【问题讨论】:
-
我不确定是否会因为一两次加入而毁掉你的表现。通过适当的索引、调整,也许还有一些应用缓存,事情可能会像您需要的一样快。
-
只有在彻底测试并有证据表明您需要恢复正常形式时,才应该进行标准化。
-
即使我们添加索引,我们也需要过滤对象类型,重点是将未过滤的数据发送给客户端。
-
如果添加索引必须过滤对象类型是什么意思?您的查询将如何构建?如果 WHERE 子句中有任何内容怎么办?
-
location_dynamic_objects和location_static_objects有什么区别?
标签: mysql sql performance normalization acid