A Dimensional Modeling Manifesto

A Dimensional Modeling Manifesto

维度建模宣言

Drawing the Line Between Dimensional Modeling and ER Modeling Techniques

划清维度建模与 ER 建模技术的界线



Dimensional modeling (DM) is the name of a logical design technique often used for data warehouses. It is different from, and contrasts with, entity-relation modeling (ER). This article points out the many differences between the two techniques and draws a line in the sand. DM is the only viable technique for databases that are designed to support end-user queries in a data warehouse. ER is very useful for the transaction capture and the data administration phases of constructing a data warehouse, but it should be avoided for end-user delivery.

维度建模(Dimensional Modeling,DM)是一种常用于数据仓库的逻辑设计技术。它与实体-关系建模(ER)不同且形成对照。本文指出这两种技术的诸多差异,并划下一条明确的界线:对于以支撑最终用户查询为目的而设计的数据仓库数据库,DM 是唯一可行的技术。ER 在构建数据仓库的事务捕获和数据管理阶段非常有用,但应避免将其用于面向最终用户的交付环节。

What is ER?

什么是 ER 建模?

ER is a logical design technique that seeks to remove the redundancy in data. Imagine that we have a business that takes orders and sells products to customers. In the early days of computing (long before relational databases) when we first transferred this data to a computer, we probably captured the original paper order as a single fat record with many fields. Such a record could easily have been 1,000 bytes distributed across 50 fields. The line items of the order were probably represented as a repeating group of fields embedded in the master record. Having this data on the computer was very useful, but we quickly learned some basic lessons about storing and manipulating data. One of the lessons we learned was that data in this form was difficult to keep consistent because each record stood on its own. The customer’s name and address appeared many times, because this data was repeated whenever a new order was taken. Inconsistencies in the data were rampant, because all of the instances of the customer address were independent, and updating the customer’s address was a messy transaction.

ER 是一种致力于消除数据冗余的逻辑设计技术。设想我们有一项接订单、向客户销售产品的业务。在计算的早期年代(远在关系数据库出现之前),我们最初把这类数据搬上计算机时,多半会把原始的纸质订单捕获成一条带很多字段的"胖记录"。这样的记录很容易就有 50 个字段、1000 字节。订单的行项目可能以嵌入主记录的重复字段组来表示。把数据放上计算机很有用,但我们很快学到了关于存储与操纵数据的一些基本教训:这种形态的数据很难保持一致,因为每条记录都各自独立。客户的姓名和地址出现了很多次,因为每接一张新订单这些数据就要重复一遍。数据不一致泛滥成灾,因为客户地址的每一处副本都彼此独立,更新客户地址成了一团乱麻。

Even in the early days, we learned to separate out the redundant data into distinct tables, such as a customer master and a product master — but we paid a price. Our software systems for retrieving and manipulating the data became complex and inefficient because they required careful attention to the processing algorithms for linking these sets of tables together. We needed a database system that was very good at linking tables. This paved the way for the relational database revolution, where the database was devoted to just this task.

即使在早期,我们也学会了把冗余数据分离到独立的表中,比如客户主表和产品主表——但我们付出了代价。检索和操纵数据的软件系统变得复杂而低效,因为它们需要小心翼翼地处理把这些表联结到一起的算法。我们需要一个特别擅长联结表的数据库系统。这为关系数据库革命铺平了道路——那场革命中的数据库正专注于此。

The relational database revolution bloomed in the mid 1980s. Most of us learned what a relational database was by reading Chris Date’s seminal book on the subject, An Introduction to Relational Databases (Addison-Wesley), first published in the early 1980s. As we paged through Chris’s book, we worked through all of his Parts, Suppliers, and Cities database examples. It didn’t occur to most of us to ask whether the data was completely “normalized” or whether any of the tables could be “snowflaked,” and Chris didn’t develop these topics. In my opinion, Chris was trying to explain the more fundamental concepts of how to think about tables that were relationally joined. ER modeling and normalization were developed in later years as the industry shifted its attention to transaction processing.

关系数据库革命在 20 世纪 80 年代中期蓬勃兴起。我们中的大多数人是通过读 Chris Date 关于这一主题的开创性著作《关系数据库导论》(An Introduction to Relational Databases,Addison-Wesley,初版于 20 世纪 80 年代初)学会什么是关系数据库的。翻阅这本书时,我们一步步做过书中所有 Parts、Suppliers 和 Cities 的数据库示例。我们中的大多数人并没有去问数据是否已经完全"规范化"、某张表是否可以"雪花化",Chris 也没有展开这些主题。在我看来,Chris 当时想解释的是更基本的概念——如何思考以关系方式联结的表。ER 建模与规范化是后来几年随着产业界把注意力转向事务处理才发展起来的。

The ER modeling technique is a discipline used to illuminate the microscopic relationships among data elements. The highest art form of ER modeling is to remove all redundancy in the data. This is immensely beneficial to transaction processing because transactions are made very simple and deterministic. The transaction of updating a customer’s address may devolve to a single record lookup in a customer address master table. This lookup is controlled by a customer address key, which defines uniqueness of the customer address record and allows an indexed lookup that is extremely fast. It is safe to say that the success of transaction processing in relational databases is mostly due to the discipline of ER modeling.

ER 建模技术是一门用来照亮数据元素之间微观关系的学科。ER 建模的最高艺术形态是消除数据中的全部冗余。这对事务处理极有裨益,因为事务因此变得非常简单而确定。更新客户地址的事务可能简化为在客户地址主表里做一次单记录查找。这次查找由一个客户地址键控制,该键定义了客户地址记录的唯一性,并支持极快的索引查找。可以这么说,关系数据库中事务处理的成功,大部分要归功于 ER 建模的这门纪律。

However, in our zeal to make transaction processing efficient, we have lost sight of our original, most important goal. We have created databases that cannot be queried! Even our simple order-taking example creates a database of dozens of tables that are linked together by a bewildering spider web of joins. (See Figure 1) All of us are familiar with the big chart on the wall of the IS database designer’s cubicle. The ER model for the enterprise has hundreds of logical entities! High-end systems such as SAP have thousands of entities. Each of these entities usually turns into a physical table when the database is implemented. This situation is not just an annoyance, it is a showstopper:

然而,在让事务处理变得高效的狂热中,我们迷失了最初也是最重要的目标。我们造出了无法被查询的数据库!就连前面那个简单的接单例子,也会造出一张由几十张表组成的数据库,表与表之间靠一张令人眼花缭乱的联结蛛网连在一起。(见图 1)我们都很熟悉 IS 数据库设计师隔间墙上的那张大图:企业级 ER 模型拥有数百个逻辑实体!SAP 这类高端系统则有数千个实体。数据库实现时,每个实体通常都会变成一张物理表。这种局面不只是恼人,它是致命的:

  • End users cannot understand or remember an ER model. End users cannot navigate an ER model. There is no graphical user interface (GUI) that takes a general ER model and makes it usable by end users.
  • Software cannot usefully query a general ER model. Cost-based optimizers that attempt to do this are notorious for making the wrong choices, with disastrous consequences for performance.
  • Use of the ER modeling technique defeats the basic allure of data warehousing, namely intuitive and high-performance retrieval of data.
  • 最终用户无法理解也无法记住一个 ER 模型;他们无法在 ER 模型中导航。没有任何图形用户界面(GUI)能把一个通用的 ER 模型变得让最终用户可用。
  • 软件无法有效地查询一个通用 ER 模型。试图这么做的基于成本的优化器以选错执行路径而臭名昭著,性能后果是灾难性的。
  • 使用 ER 建模技术会葬送数据仓库最根本的魅力——直观而高性能的数据检索。

Ever since the beginning of the relational database revolution, IS shops have noticed this problem. Many of them that have tried to deliver data to end users have recognized the impossibility of presenting these immensely complex schemas to end users, and many of these IS shops have stepped back to attempt “simpler designs.” I find it striking that these “simpler” designs all look very similar! Almost all of these simpler designs can be thought of as “dimensional.” In a natural, almost unconscious way, hundreds of IS designers have returned to the roots of the original relational model because they know the database cannot be used unless it is packaged simply. It is probably accurate to say that this natural dimensional approach was not invented by any single person. It is an irresistible force in the design of databases that will always appear when the designer places understandability and performance as the highest goals. We are now ready to define the DM approach.

自关系数据库革命伊始,IS 部门就注意到了这个问题。许多尝试向最终用户交付数据的部门,都意识到把这些无比复杂的模式呈现给最终用户是不可能的,其中不少 IS 部门退回去尝试"更简单的设计"。令我印象深刻的是,这些"更简单"的设计看起来都非常相似!几乎所有这些更简单的设计都可以被视为"维度化"的。数百名 IS 设计师以一种自然的、几乎是无意识的方式,回到了最初关系模型的根源,因为他们知道:除非把数据库包装得简单,否则它就没法用。可以说,这种自然的维度化方法并非由某一个人发明。它是数据库设计中一股不可抗拒的力量——只要设计者把可理解性和性能置于最高目标,它就必然出现。现在,我们可以给 DM 方法下定义了。

What is DM?

什么是 DM?

DM is a logical design technique that seeks to present the data in a standard, intuitive framework that allows for high-performance access. It is inherently dimensional, and it adheres to a discipline that uses the relational model with some important restrictions. Every dimensional model is composed of one table with a multipart key, called the fact table, and a set of smaller tables called dimension tables. Each dimension table has a single-part primary key that corresponds exactly to one of the components of the multipart key in the fact table. (See Figure 1.) This characteristic “star-like” structure is often called a star join. The term star join dates back to the earliest days of relational databases.

DM 是一种逻辑设计技术,它力图以一个标准、直观的框架来呈现数据,从而支持高性能的访问。它天然是维度化的,并遵循一套带若干重要限制的关系模型纪律。每个维度模型都由一张带复合键的表(称为事实表)和一组更小的表(称为维度表)组成。每张维度表都有一个单字段主键,与事实表复合键中的某个组成部分恰好一一对应。(见图 1)这种特征性的"星状"结构通常被称为星型联结(star join)。星型联结一词可以追溯到关系数据库的最早年代。

Manifesto figure

Manifesto figure

A fact table, because it has a multipart primary key made up of two or more foreign keys, always expresses a many-to-many relationship. The most useful fact tables also contain one or more numerical measures, or “facts,” that occur for the combination of keys that define each record. In Figure 1, the facts are Dollars Sold, Units Sold, and Dollars Cost. The most useful facts in a fact table are numeric and additive. Additivity is crucial because data warehouse applications almost never retrieve a single fact table record; rather, they fetch back hundreds, thousands, or even millions of these records at a time, and the only useful thing to do with so many records is to add them up.

事实表的主键由两个或更多外键复合而成,因此它总是表达多对多关系。最有用的事实表还包含一个或多个数值型度量(即"事实"),这些度量对应于定义每条记录的键组合。在图 1 中,事实是销售金额(Dollars Sold)、销售数量(Units Sold)和成本金额(Dollars Cost)。事实表中最有用的事实是数值型且可加的。可加性至关重要,因为数据仓库应用几乎从不检索单条事实表记录,而是一次取回成百上千甚至上百万条记录——面对这么多记录,唯一有用的操作就是把它们加起来。

Dimension tables, by contrast, most often contain descriptive textual information. Dimension attributes are used as the source of most of the interesting constraints in data warehouse queries, and they are virtually always the source of the row headers in the SQL answer set. In Figure 1, we constrain on the Lemon flavored products via the Flavor attribute in the Product table, and on Radio promotions via the AdType attribute in the Promotion table. It should be obvious that the power of the database in Figure 1 is proportional to the quality and depth of the dimension tables.

与之相对,维度表大多包含描述性的文本信息。维度属性是数据仓库查询中大多数有趣约束的来源,也几乎总是 SQL 结果集中行标题的来源。在图 1 中,我们通过 Product 表的 Flavor 属性约束柠檬味产品,通过 Promotion 表的 AdType 属性约束电台促销。显而易见,图 1 中数据库的威力与维度表的质量和深度成正比。

The charm of the database design in Figure 1 is that it is highly recognizable to the end users in the particular business. I have observed literally hundreds of instances where end users agree immediately that this is “their business.”

图 1 中这种数据库设计的迷人之处在于:特定业务中的最终用户一眼就能认出它。我见过数以百计的实例,最终用户立刻就认可"这就是我们的业务"。

DM vs. ER

DM 与 ER 的关系

The key to understanding the relationship between DM and ER is that a single ER diagram breaks down into multiple DM diagrams. Think of a large ER diagram as representing every possible business process in the enterprise. The master ER diagram may have Sales Calls, Order Entries, Shipment Invoices, Customer Payments, and Product Returns, all on the same diagram. In a way, the ER diagram does itself a disservice by representing on one diagram multiple processes that never coexist in a single data set at a single consistent point in time. It’s no wonder the ER diagram is overly complex. Thus the first step in converting an ER diagram to a set of DM diagrams is to separate the ER diagram into its discrete business processes and to model each one separately.

理解 DM 与 ER 之间关系的关键在于:一张 ER 图会分解为多张 DM 图。把一张大 ER 图想象为代表企业中每一个可能的业务过程。这张主 ER 图上可能同时画着销售拜访、订单录入、发运发票、客户付款和产品退货。从某种意义上说,ER 图这是自找麻烦——它把在单一数据集、单一一致时点内永远不会共存的多个过程画在了一张图上。难怪 ER 图会过度复杂。因此,把 ER 图转换为一组 DM 图的第一步,是把 ER 图拆分成一个个离散的业务过程,并对每个过程分别建模。

The second step is to select those many-to-many relationships in the ER model containing numeric and additive nonkey facts and to designate them as fact tables. The third step is to denormalize all of the remaining tables into flat tables with single-part keys that connect directly to the fact tables. These tables become the dimension tables. In cases where a dimension table connects to more than one fact table, we represent this same dimension table in both schemas, and we refer to the dimension tables as “conformed” between the two dimensional models.

第二步,是在 ER 模型中选出那些包含数值型、可加的非键事实的多对多关系,把它们指定为事实表。第三步,是把其余所有表反规范化为带单字段键的扁平表,直接连接到事实表上——这些表就成为维度表。当一张维度表连接到多张事实表时,我们在两个模式中都表示同一张维度表,并称这些维度表在两个维度模型之间是"一致的"(conformed,即一致性维度)。

The resulting master DM model of a data warehouse for a large enterprise will consist of somewhere between 10 and 25 very similar-looking star join schemas. Each star join will have four to 12 dimension tables. If the design has been done correctly, many of these dimension tables will be shared from fact table to fact table. Applications that drill down will simply be adding more dimension attributes to the SQL answer set from within a single star join. Applications that drill across will simply be linking separate fact tables together through the conformed (shared) dimensions. Even though the overall suite of star join schemas in the enterprise dimensional model is complex, the query processing is very predictable because at the lowest level, I recommend that each fact table should be queried independently.

最终,一个大型企业数据仓库的主 DM 模型将由 10 到 25 个外观非常相似的星型联结模式构成。每个星型联结有 4 到 12 张维度表。如果设计做得正确,许多维度表会在事实表之间共享。下钻(drill down)应用只是在单个星型联结内,向 SQL 结果集添加更多维度属性。跨钻(drill across)应用只是通过一致性(共享)维度把不同的事实表联结起来。尽管企业维度模型中整套星型联结模式很复杂,但查询处理是高度可预测的,因为在最低层级,我建议每张事实表都独立地被查询。

The Strengths of DM

DM 的优势

The dimensional model has a number of important data warehouse advantages that the ER model lacks. First, the dimensional model is a predictable, standard framework. Report writers, query tools, and user interfaces can all make strong assumptions about the dimensional model to make the user interfaces more understandable and to make processing more efficient. For instance, because nearly all of the constraints set up by the end user come from the dimension tables, an end-user tool can provide high-performance “browsing” across the attributes within a dimension via the use of bit vector indexes. Metadata can use the known cardinality of values in a dimension to guide the user-interface behavior. The predictable framework offers immense advantages in processing. Rather than using a cost-based optimizer, a database engine can make very strong assumptions about first constraining the dimension tables and then “attacking” the fact table all at once with the Cartesian product of those dimension table keys satisfying the user’s constraints. Amazingly, by using this approach it is possible to evaluate arbitrary n-way joins to a fact table in a single pass through the fact table’s index. We are so used to thinking of n-way joins as “hard” that a whole generation of DBAs doesn’t realize that the n-way join problem is formally equivalent to a single sort-merge. Really.

维度模型拥有若干 ER 模型所缺乏的重要数仓优势。第一,维度模型是一个可预测的、标准的框架。报表工具、查询工具和用户界面都可以对维度模型做出强假设,从而让界面更易懂、处理更高效。例如,由于最终用户设置的约束几乎全部来自维度表,最终用户工具可以利用位图索引,在维度内的属性之间提供高性能的"浏览"。元数据可以利用维度中值的已知基数来引导界面行为。可预测的框架在处理上带来巨大优势:数据库引擎无需依赖基于成本的优化器,而是可以先约束维度表,再用满足用户约束的那些维度表键的笛卡尔积,一次性"进攻"事实表——做出非常强的假设。神奇的是,用这种方法,穿过事实表索引的一趟扫描就能完成对事实表任意 n 路联结的求值。我们太习惯于把 n 路联结当成"难"的问题,以至于整整一代 DBA 都没有意识到:n 路联结问题在形式上等价于一次排序-归并。真的。

A second strength of the dimensional model is that the predictable framework of the star join schema withstands unexpected changes in user behavior. Every dimension is equivalent. All dimensions can be thought of as symmetrically equal entry points into the fact table. The logical design can be done independent of expected query patterns. The user interfaces are symmetrical, the query strategies are symmetrical, and the SQL generated against the dimensional model is symmetrical.

维度模型的第二个优势是:星型联结模式的可预测框架能经受住用户行为的意外变化。每个维度都是等价的。所有维度都可以被视为进入事实表的对称等价入口。逻辑设计可以独立于预期的查询模式来完成。用户界面对称、查询策略对称、针对维度模型生成的 SQL 也对称。

A third strength of the dimensional model is that it is gracefully extensible to accommodate unexpected new data elements and new design decisions. When we say gracefully extensible, we mean several things. First, all existing tables (both fact and dimension) can be changed in place by simply adding new data rows in the table, or the table can be changed in place with a SQL alter table command. Data should not have to be reloaded. Graceful extensibility also means that that no query tool or reporting tool needs to be reprogrammed to accommodate the change. And finally, graceful extensibility means that all old applications continue to run without yielding different results. In Figure 1, I labeled the schema with the numbers 1 through 4 indicating where you can, respectively, make the following graceful changes to the design after the data warehouse is up and running by:

维度模型的第三个优势是:它可以优雅地扩展,以容纳意料之外的新数据元素和新的设计决策。所谓优雅扩展,包含几层意思。首先,所有现有表(事实表和维度表)都可以原地变更——只需在表中加入新的数据行,或用 SQL 的 alter table 命令原地修改表结构,数据无需重载。优雅扩展还意味着:任何查询工具或报表工具都无需重新编程来适应变更。最后,优雅扩展意味着所有旧应用继续运行,且不产生不同的结果。在图 1 中,我标了 1 到 4 的编号,指出数仓上线运行后可以在哪些位置做如下优雅变更:

  1. Adding new unanticipated facts (that is, new additive numeric fields in the fact table), as long as they are consistent with the fundamental grain of the existing fact table
  2. Adding completely new dimensions, as long as there is a single value of that dimension defined for each existing fact record
  3. Adding new, unanticipated dimensional attributes
  4. Breaking existing dimension records down to a lower level of granularity from a certain point in time forward.
  1. 增加未曾预料的新事实(即事实表中新的可加数值字段),只要它们与现有事实表的基本粒度一致
  2. 增加全新的维度,只要每个现有事实记录对该维度都有单一取值
  3. 增加新的、未曾预料的维度属性
  4. 把现有维度记录从某个时点起向下拆分到更细的粒度

A fourth strength of the dimensional model is that there is a body of standard approaches for handling common modeling situations in the business world. Each of these situations has a well-understood set of alternatives that can be specifically programmed in report writers, query tools, and other user interfaces. These modeling situations include:

维度模型的第四个优势是:针对商业世界中常见的建模情境,已经形成了一套标准的处理方法。每种情境都有一组被充分理解的备选方案,可以在报表工具、查询工具和其他用户界面中被专门编程实现。这些建模情境包括:

  • Slowly changing dimensions, where a “constant” dimension such as Product or Customer actually evolves slowly and asynchronously. Dimensional modeling provides specific techniques for handling slowly changing dimensions, depending on the business environment. See my DBMS article of April 1996 on slowly changing dimensions.
  • Heterogeneous products, where a business such as a bank needs to track a number of different lines of business together within a single common set of attributes and facts, but at the same time it needs to describe and measure the individual lines of business in highly idiosyncratic ways using incompatible measures.
  • Pay-in-advance databases, where the transactions of a business are not little pieces of revenue, but the business needs to look at the individual transactions as well as report on revenue on a regular basis. For this and the previous bullet, see my DBMS article of December 1995, the insurance company case study.
  • Event-handling databases, where the fact table usually turns out to be “factless.” See my DBMS article of September 1996 on factless fact tables.
  • 缓慢变化维度:诸如产品或客户这类"恒定"的维度实际上在缓慢且异步地演化。维度建模针对缓慢变化维度提供了具体技术,可依业务环境选用。参见我 1996 年 4 月发表在 DBMS 上关于缓慢变化维度的文章。
  • 异构产品:像银行这样的业务,需要在一套通用的属性和事实中同时跟踪多条不同的业务线,同时又需要以高度个性化的方式、用互不兼容的度量来描述和度量每条业务线。
  • 预收型数据库:这类业务的交易并不是一笔笔小额收入,但业务既需要查看单笔交易,也需要定期汇报收入。这一条以及上一条,参见我 1995 年 12 月发表在 DBMS 上的保险公司案例研究。
  • 事件型数据库:事实表最终往往是"无事实"的。参见我 1996 年 9 月发表在 DBMS 上关于无事实事实表的文章。

A final strength of the dimensional model is the growing body of administrative utilities and software processes that manage and use aggregates. Recall that aggregates are summary records that are logically redundant with base data already in the data warehouse, but they are used to enhance query performance. A comprehensive aggregate strategy is required in every medium- and large-sized data warehouse implementation. To put it another way, if you don’t have aggregates, then you are potentially wasting millions of dollars on hardware upgrades to solve performance problems that could be otherwise addressed by aggregates.

维度模型的最后一个优势,是管理与使用聚合(aggregate)的管理工具和软件流程正在不断壮大。回顾一下:聚合是与数仓中已有基础数据逻辑冗余的汇总记录,用来提升查询性能。每个中大型数仓实施都需要一套完整的聚合策略。换个说法:如果你没有聚合,那你就是在白白浪费数百万美元的硬件升级费用,去解决本可以用聚合解决的问题。

All of the aggregate management software packages and aggregate navigation utilities depend on a very specific single structure of fact and dimension tables that is absolutely dependent on the dimensional model. If you don’t adhere to the dimensional approach, you cannot benefit from these tools. Please see my DBMS articles on aggregate navigation and the various products serving aggregate navigation in the September 1995 and August 1996 issues.

所有聚合管理软件包和聚合导航工具都依赖一个非常特定的、完全建立在维度模型之上的事实表与维度表结构。如果你不遵循维度方法,你就无法从这些工具中获益。请参阅我在 1995 年 9 月刊和 1996 年 8 月刊上关于聚合导航及各类聚合导航产品的 DBMS 文章。

Myths About DM

关于 DM 的迷思

A few myths floating around about dimensional modeling deserve to be addressed. Myth number one is “Implementing a dimensional data model will lead to stovepipe decision-support systems.” This myth sometimes goes on to blame denormalization for supporting only specific applications that therefore cannot be changed. This myth is a short-sighted interpretation of dimensional modeling that has managed to get the message exactly backwards! First, we have argued that every ER model has an equivalent set of DM models that contain the same information. Second, we have shown that even in the presence of organizational change and end-user adaptation, the dimensional model extends gracefully without altering its form. It is in fact the ER model that whipsaws the application designers and the end users!

关于维度建模流传着几个迷思,值得正面回应。迷思一:"实施维度数据模型会导致烟囱式的决策支持系统。"这个迷思有时还会进一步把账算到反规范化头上,说它只支撑特定应用、因而无法变更。这是对维度建模的短视解读,而且把信息完全传反了!第一,我们已经论证过:每个 ER 模型都有一组等价的 DM 模型,包含同样的信息。第二,我们已经展示过:即便面对组织变革和最终用户的适应调整,维度模型也能在不改变形态的前提下优雅扩展。真正让应用设计师和最终用户无所适从的,恰恰是 ER 模型!

A source of this myth, in my opinion, is the designer who is struggling with fact tables that have been prematurely aggregated. For instance, the design in Figure 1 is expressed at the individual sales-ticket line-item level. This is the correct starting point for this retail database because this is the lowest possible grain of data. There just isn’t any further breakdown of the sales transaction. If the designer had started with a fact table that had been aggregated up to weekly sales totals by store, then there would be all sorts of problems in adding new dimensions, new attributes, and new facts. However, this isn’t a problem with the design technique, this is a problem with the database being prematurely aggregated.

在我看来,这个迷思的一个来源,是那些正在与"被过早聚合的事实表"搏斗的设计师。例如,图 1 中的设计表达在单个销售小票行项目的层级。对这家零售数据库而言,这是正确的起点,因为这是数据可能的最低粒度——销售事务再也无法进一步拆分了。如果设计师当初从"按门店聚合到每周销售总额"的事实表出发,那么在增加新维度、新属性、新事实时就会遇到各种各样的问题。然而这不是设计技术本身的问题,这是数据库被过早聚合的问题。

Myth number two is “No one understands dimensional modeling.” This myth is absurd. I have seen hundreds of excellent dimensional designs created by people I have never met or had in my classes. A whole generation of designers from the packaged-goods retail and manufacturing industries has been using and designing dimensional databases for the last 15 years. I personally learned about dimensional models from existing A.C. Nielsen and IRI applications that were installed and working in such places as Procter & Gamble and The Clorox Company as early as 1982.

迷思二:"没人懂维度建模。"这个迷思很荒谬。我见过数以百计的优秀维度设计,出自与我素未谋面、也从未上过我课的人之手。整整一代来自快消零售与制造行业的设计师,在过去 15 年里一直在使用并设计维度数据库。我本人最早了解维度模型,是通过早在 1982 年就安装运行在宝洁和高乐氏等公司的 A.C. Nielsen 和 IRI 现成应用。

Incidentally, although this article has been couched in terms of relational databases, nearly all of the arguments in favor of the power of dimensional modeling hold perfectly well for proprietary multidimensional databases such as Oracle Express and Arbor Essbase.

顺带一提,尽管本文是以关系数据库的语言来表述的,但支持维度建模威力的几乎所有论点,对 Oracle Express 和 Arbor Essbase 这类专有多维数据库同样完全成立。

Myth number three is “Dimensional models only work with retail databases.” This myth is rooted in the historical origins of dimensional modeling but not in its current-day reality. Dimensional modeling has been applied to many different business areas including retail banking, commercial banking, property and casualty insurance, health insurance, life insurance, brokerage customer analysis, telephone company operations, newspaper advertising, oil company fuel sales, government agency spending, and manufacturing shipments.

迷思三:"维度模型只适用于零售数据库。"这个迷思源于维度建模的历史起源,但与它今天的现实不符。维度建模已被应用于众多业务领域,包括零售银行、商业银行、财产与意外险、健康险、寿险、经纪客户分析、电信运营、报纸广告、石油公司燃油销售、政府机构支出以及制造业发货。

Myth number four is “Snowflaking is an alternative to dimensional modeling.” Snowflaking is the removal of low-cardinality textual attributes from dimension tables and the placement of these attributes in “secondary” dimension tables. For instance, a product category can be treated this way and physically removed from the low-level product dimension table. I believe that this method compromises cross-attribute browsing performance and may interfere with the legibility of the database, but I know that some designers are convinced that this is a good approach. Snowflaking is certainly not at odds with dimensional modeling. I regard snowflaking as an embellishment to the cleanliness of the basic dimensional model. I think that a designer can snowflake with a clear conscience if this technique improves user understandability and improves overall performance. The argument that snowflaking helps the maintainability of the dimension table is specious. Maintenance issues are indeed leveraged by ER-like disciplines, but all of this happens in the operational data store, before the data is loaded into the dimensional schema.

迷思四:"雪花化是维度建模的替代方案。"雪花化是指把低基数的文本属性从维度表中移出,放进"二级"维度表。例如,产品类别可以这样处理,从底层的商品维度表中物理移出。我认为这种方法损害了跨属性浏览的性能,还可能妨碍数据库的易读性,但我知道有些设计师确信这是好方法。雪花化当然与维度建模并不冲突。我把雪花化视为对基本维度模型整洁性的一种修饰。如果这种技术能提升用户的可理解性并改善整体性能,设计师尽可以问心无愧地雪花化。"雪花化有助于维度表可维护性"的论点是似是而非的。类 ER 的纪律确实能放大可维护性,但所有这些发生在操作型数据存储(ODS)里,在数据被装载进维度模式之前。

The final myth is “Dimensional modeling only works for certain kinds of single-subject data marts.” This myth is an attempt to marginalize dimensional modeling by individuals who do not understand its fundamental power and applicability. Dimensional modeling is the appropriate technique for the overall design of a complete enterprise-level data warehouse. Such a dimensional design consists of families of dimensional models, where each family describes a business process. The families are linked together in an effective way by insisting on the use of conformed dimensions.

最后一个迷思是:"维度建模只适用于某种单一主题的数据集市。"这个迷思是一些不理解维度建模根本力量与适用性的人,试图把它边缘化的说辞。维度建模同样是一个完整的企业级数据仓库总体设计的合宜技术。这样的维度设计由一族维度模型构成,每一族描述一个业务过程。通过坚持使用一致性维度,各族之间以有效的方式联结在一起。

In Defense of DM

为 DM 辩护

Now it’s time to take off the gloves. I firmly believe that dimensional modeling is the only viable technique for designing end-user delivery databases. ER modeling defeats end-user delivery and should not be used for this purpose.

现在到了摊牌的时刻。我坚定地相信:在设计面向最终用户的交付数据库时,维度建模是唯一可行的技术。ER 建模与最终用户交付是相克的,不应为此目的使用。

ER modeling does not really model a business; rather, it models the micro relationships among data elements. ER modeling does not have “business rules,” it has “data rules.” Few if any global design requirements in the ER modeling methodology speak to the completeness of the overall design. For instance, does your ER CASE tool try to tell you if all of the possible join paths are represented and how many there are? Are you even concerned with such issues in an ER design? What does ER have to say about standard business modeling situations such as slowly changing dimensions?

ER 建模真正建模的并不是业务,而是数据元素之间的微观关系。ER 建模没有"业务规则",只有"数据规则"。ER 建模方法论中几乎没有任何全局设计要求去关注整体设计的完整性。例如,你的 ER CASE 工具会告诉你所有可能的联结路径是否都已表达、一共有多少条吗?你在 ER 设计中甚至关心过这类问题吗?对于缓慢变化维度这类标准的业务建模情境,ER 又说了什么?

ER models are wildly variable in structure. Tell me in advance how to optimize the querying of hundreds of interrelated tables in a big ER model. By contrast, even a big suite of dimensional models has an overall deterministic strategy for evaluating every possible query, even those crossing many fact tables. (Hint: You control performance by querying each fact table separately. If you actually believe that you can join many fact tables together in a single query and trust a cost-based optimizer to decide on the execution plan, then you haven’t implemented a data warehouse for real end users.)

ER 模型的结构千变万化。请预先告诉我,该如何优化一个大型 ER 模型中数百张相互关联的表的查询?相比之下,即便是一大套维度模型,对每一个可能的查询——哪怕跨越许多张事实表——也有一个总体确定性的求值策略。(提示:你通过逐张独立查询事实表来控制性能。如果你真的相信可以把许多事实表联结进一个查询、并把执行计划交给基于成本的优化器去决定,那你还没有为真正的最终用户实施过数据仓库。)

The wild variability of the structure of ER models means that each data warehouse needs custom, handwritten and tuned SQL. It also means that each schema, once it is tuned, is very vulnerable to changes in the user’s querying habits, because such schemas are asymmetrical. By contrast, in a dimensional model all dimensions serve as equal entry points to the fact table. Changes in users’ querying habits don’t change the structure of the SQL or the standard ways of measuring and controlling performance.

ER 模型结构的剧烈可变性,意味着每个数仓都需要定制的、手写的、手工调优的 SQL。这也意味着每个模式一旦调优完成,就非常脆弱——用户的查询习惯一变就失灵,因为这样的模式是非对称的。相比之下,在维度模型中,所有维度都是进入事实表的平等入口。用户查询习惯的变化,不会改变 SQL 的结构,也不会改变度量和控制性能的标准方法。

ER models do have their place in the data warehouse. First, the ER model should be used in all legacy OLTP applications based on relational technology. This is the best way to achieve the highest transaction performance and the highest ongoing data integrity. Second, the ER model can be used very successfully in the back-room data cleaning and combining steps of the data warehouse. This is the ODS, or operational data store.

ER 模型在数据仓库中确实有其位置。第一,所有基于关系技术的遗留 OLTP 应用都应当使用 ER 模型,这是获得最高事务性能和最高持续数据完整性的最佳途径。第二,ER 模型可以非常成功地用于数据仓库后台的数据清洗与合并步骤。这就是 ODS,即操作型数据存储。

However, before data is packaged into its final queryable format, it must be loaded into a dimensional model. The dimensional model is the only viable technique for achieving both user understandability and high query performance in the face of ever-changing user questions.

然而,在数据被包装成最终可查询的形态之前,必须先装载进维度模型。要在不断变化的用户问题面前同时实现用户可理解性与高查询性能,维度建模是唯一可行的技术。