构建物化视图的两种方式

2018-05-04 10:46:56 浏览数 (1)

构建物化视图的两种方式

章节:nosql distilled 第三章第四节 物化视图

There are two rough strategies to building a materialized view. The first is the eager approach where you update the materialized view at the same time you update the base data for it.

现在啊,我们有两种略显粗糙的办法来构建一个物化视图。

第一种是一种即时的方式,就是一旦基础数据更新了马上就去更新物化视图。

In this case, adding an order would also update the purchase history aggregates for each product.

在这种情况下,添加一条订单也会为每个产品更新购买历史纪录的那个聚合(也就是那个物化视图)。

This approach is good when you have more frequent reads of the materialized view than you have writes and you want the materialized views to be as fresh as possible.

这个方法非常适合哪种在你读取操作比写入操作频繁并且你希望那个物化视图的数据尽可能是最新的数据。在这种情况下,这种即时构建的方法很适合。

The application database (p. 7) approach is valuable here as it makes it easier to ensure that any updates to base data also update materialized views.

像应用数据库的解决方案就是非常适合这种情况。因为它可以很容易的确保当原始数据更新的时候,物化视图也会同时被更新。

If you don’t want to pay that overhead on each update, you can run batch jobs to update the materialized views at regular intervals. You’ll need to understand your business requirements to assess how stale your materialized views can be.

如果你不想在每次更新基础数据的时候就去更新物化视图,你可以运行一个批处理任务定时去更新你的物化视图。但你得先去看看你的具体业务需求中对于物化视图的新鲜程度的要求,然后再来确定隔好久更新一次。

You can build materialized views outside of the database by reading the data, computing the view, and saving it back to the database.

你可以在数据库之外构建物化视图:先读取数据,然后计算出结果,最后把结果保存进数据库。

More often databases will support building materialized views themselves. In this case, you provide the computation that needs to be done, and the database executes the computation when needed according to some parameters that you configure. This is particularly handy for eager updates of views with incremental map-reduce (“ Incremental Map- Reduce,” p. 76).

大部分的数据库都支持内部构建物化视图。在这种情况下,你告诉数据库需要做哪些计算,然后数据库会在需要的时候根据你配置好的参数进行计算。这个对于使用增量式maprduce来即时更新视图的情况非常方便。

Materialized views can be used within the same aggregate.

An order document might include an order summary element that provides summary information about the order so that a query for an order summary does not have to transfer the entire order document.

Using different column families for materialized views is a common feature of column-family databases.

An advantage of doing this is that it allows you to update the materialized view within the same atomic operation.

物化视图也可以在同一个聚合内使用。一个订单文档中可能包含那种为订单提供摘要信息的element(就是文档中有个element)。所以呢,当你去查询有关订单摘要信息的时候,数据库并不会transfer(穿越)整个订单的这个dom。

为不同的列族来构建物化视图是一个列族数据库们的常用功能,也就是标配。

这么做的好处就是你更新物化视图的时候具备了事务能力,其实就是那个ACID啦。

好啦,这就是我们今天的内容!

0 人点赞