反规范化是什么意思?
What does denormalizing mean?
在阅读文章 http://blog.mongodb.org/post/88473035333/6-rules-of-thumb-for-mongodb-schema-design-part-3 章节:“经验法则:彩虹之路指南”时,我遇到了词:嵌入和非规范化。
One: favor embedding unless there is a compelling reason not to
Five: Consider the write/read ratio when denormalizing. A field that will mostly be read and only seldom updated is a good candidate for denormalization: if you denormalize a field that is updated frequently then the extra work of finding and updating all the instances is likely to overwhelm the savings that you get from denormalizing.
我知道嵌入是嵌套文档,而不是单独写tables/collections。
但我不知道反规范化是什么意思。
反规范化与 normalization 相反,后者是设计关系数据库(如 MySQL)的一种良好做法,您可以将一个逻辑数据集拆分为单独的 table 以减少冗余。
因为 MongoDB 不支持 table 的连接,如果经常读取属性且更新较少,您更愿意将属性复制到两个集合中。
例如:您想保存有关某个人的数据并想保存此人的性别:
在 SQL 数据库中,您将创建一个 table 人和一个 table 性别,将性别 ID 的外键存储在人 table 中并执行加入以获取完整信息。这样 "male" 和 "female" 只作为一个值存在一次。
在 MongoDB 中,您将保存每个人的性别,因此值 "male" 和 "female" 可以存在多次,但查找速度更快,因为数据紧密耦合在一个集合对象。
在阅读文章 http://blog.mongodb.org/post/88473035333/6-rules-of-thumb-for-mongodb-schema-design-part-3 章节:“经验法则:彩虹之路指南”时,我遇到了词:嵌入和非规范化。
One: favor embedding unless there is a compelling reason not to
Five: Consider the write/read ratio when denormalizing. A field that will mostly be read and only seldom updated is a good candidate for denormalization: if you denormalize a field that is updated frequently then the extra work of finding and updating all the instances is likely to overwhelm the savings that you get from denormalizing.
我知道嵌入是嵌套文档,而不是单独写tables/collections。
但我不知道反规范化是什么意思。
反规范化与 normalization 相反,后者是设计关系数据库(如 MySQL)的一种良好做法,您可以将一个逻辑数据集拆分为单独的 table 以减少冗余。
因为 MongoDB 不支持 table 的连接,如果经常读取属性且更新较少,您更愿意将属性复制到两个集合中。
例如:您想保存有关某个人的数据并想保存此人的性别:
在 SQL 数据库中,您将创建一个 table 人和一个 table 性别,将性别 ID 的外键存储在人 table 中并执行加入以获取完整信息。这样 "male" 和 "female" 只作为一个值存在一次。
在 MongoDB 中,您将保存每个人的性别,因此值 "male" 和 "female" 可以存在多次,但查找速度更快,因为数据紧密耦合在一个集合对象。