简体   繁体   English

我应该根据活动拆分表吗?

[英]Should I split tables based on activity?

I'm working on a hobby project that is a online game. 我正在从事一个在线游戏的爱好项目。 That game stores player data in one big flat file. 该游戏将玩家数据存储在一个大的平面文件中。 The data itself contains all the information of the player from Name to even items on the player itself. 数据本身包含播放器的所有信息,从名称到播放器本身的所有项目。 It's a rather large amount of columns by itself and having dozens of items only increases the flat file size to boot. 它本身具有大量的列,并且具有数十个项目只会增加启动平面文件的大小。

To give you a visual. 给你视觉。 My current player file is 192 columns (not accounting for items). 我当前的播放器文件为192列(不计项目)。

Player Data 玩家资料

There is 51 columns in my flat files for player data after I reduced the fluff. 减少绒毛之后,平面文件中有51列用于播放器数据。 This does not include the items or the abilities for the players. 这不包括玩家的物品或能力。 I've already decided those can be separated into separate tables and linked with a FK. 我已经决定可以将它们分离到单独的表中并与FK链接。

The 51 columns of data are unique to the player and should not be duplicated. 这51列数据对播放器而言是唯一的,不应重复。 They are not what I've been told as good candidates for normalization. 他们并不是我被告知可以进行标准化的理想人选。

Table

  • id ID
  • name 名称
  • password 密码
  • race 种族
  • sex 性别
  • class
  • level 水平
  • gold
  • silver
  • experience 经验
  • quest 寻求
  • armor 盔甲
  • strength 强度
  • wisdom 智慧
  • dexterity 灵巧
  • etc 等等

Activity 活动

However, the activity of when some of these columns are selected and updated is vastly different from one another. 但是,选择和更新这些列中的某些列时的活动彼此之间存在很大差异。 Some are updated when the player moves, others are rarely utilized outside of when the player logs into the game and loaded into memory. 有些在玩家移动时进行更新,而另一些则很少在玩家登录游戏并加载到内存时使用。 Records are never dropped or rebuilt. 记录永远不会丢失或重建。 Every column has a value. 每列都有一个值。 frequency of activity is anywhere from every second to once a month. 活动频率从每秒到每月一次。

Question

That leads me to a question. 这引出我一个问题。 Instead of traditional way of normalizing data, can I split these columns up based on activity and increase performance if they were in the same table? 如果可以将这些列放在同一张表中,那么可以根据活动将这些列拆分开来代替传统的标准化数据的方法吗? Or should I leave them the same table all together and just rely on proper indexing? 还是我应该将它们放在同一张表中,而仅依靠适当的索引编制? Most of the columns look good to go, but like I said, some are used more than others. 大部分专栏文章看起来不错,但是就像我说的那样,有些专栏文章比其他专栏文章更多地使用。 But, there is a vast difference in when some are used more than others. 但是,何时使用某些方法比使用其他方法有很大差异。 This sort of scares me. 这吓到我了。

What you're mentioning is called denormalization and is actually a quite known and frequent matter. 您所提到的被称为非规范化 ,实际上是一个众所周知且经常发生的事情。

There are no general rules and indications as to when to denormalize. 没有关于何时进行非规范化的通用规则和指示。 This depends on so many things specific to each project (like the hardware, the type of DB, and the "activity" you mention to name a few) that it comes down to profiling each application to get to a conclusion. 这取决于每个项目所特有的许多内容(例如硬件,数据库类型以及您提到的“活动”),这取决于对每个应用程序进行概要分析以得出结论。

Also, sometimes denormalization means splitting a table into two tables with a one-to-one relationship (like in your case). 同样,有时非规范化意味着将一个表分成一对一关系的两个表(例如您的情况)。 Sometimes it means getting rid of FKs and putting everything in a BIG table with many columns to avoid the joins when selecting. 有时,这意味着要摆脱FK,并将所有内容放到具有许多列的BIG表中,以避免选择时出现联接。

Most importantly, keep in mind that your question is as much about performance than it is about scalability . 最重要的是,请记住,您的问题与性能有关,而与可扩展性无关 Separating into different tables/databases mean you could eventually store the data in different machines, each having a specific hardware architecture with a database that fits the use case. 分为不同的表/数据库意味着您最终可以将数据存储在不同的计算机中,每台计算机都具有特定的硬件体系结构以及适合该用例的数据库。


Example of denormalization in the gaming industry 游戏行业反规范化的示例

One example of denormalization I can think of when it comes to MMORPGs is to store all the unfrequently changed user data in a BLOB. 我可以想到的涉及到MMORPG的非规范化的一个示例是将所有不经常更改的用户数据存储在BLOB中。 Not only is this denormalizing, but the whole row is stored as a series of bytes. 这不仅会导致非规范化,而且整个行都将存储为一系列字节。 Dr. EF Codd wouldn't be happy at all. EF Codd博士一点都不高兴。

One company that does this is Playfish . Playfish是一家做到这一点的公司。

This means that you have faster selects at the cost of slower updates and, most importantly, changing the schema for the user becomes a real hassle (but the reasoning here is it will always be Username , Password , E-mail until the end of time). 这意味着您可以选择较快的内容 ,但要以更新较慢的代价为代价,最重要的是,为用户更改架构确实很麻烦(但是这里的理由是,直到时间结束,它始终是UsernamePasswordE-mail )。 This also means that your user data can now be stored in a simpler key/value store instead of an RDBMS with more overhead. 这也意味着您的用户数据现在可以存储在更简单的键/值存储中,而不是存储在开销更大的RDBMS中。 Of course, the login server fetching user information won't need to be as performant as the one handling the gameplay. 当然,获取用户信息的登录服务器不需要像处理游戏一样高效。


So try reading about use cases for denormalization (this is a very active topic) and see where you can apply your findings in your case. 因此,请尝试阅读有关非规范化的用例(这是一个非常活跃的主题),并查看可以在案例中应用发现的地方。 Also, keep in mind that pre-optimization can be sometimes counter-productive, maybe you should focus now on developing your game. 另外,请记住,预优化有时会适得其反,也许您现在应该专注于开发游戏。 When you have scaling/performance problems, you will most probably have the funding that comes with the high number of users to address the problem. 当您遇到扩展/性能问题时,您很可能会拥有大量用户来解决该问题。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM