物化视图更新算法(一):基础框架

520 阅读1分钟

物化视图通过将预计算的结果保存下来,能极大地减少查询时候的计算开销,提高查询效率。本文主要介绍物化视图的更新算法的基础框架,即给定一个物化视图的定义,推导出计算物化视图的变更的执行计划。

一些定义

关系代数运算符定义

我们首先定义一些关系代数运算符,其中这些运算符假设的是bag模型,而不是set模型,即一个relation里的tuple是可以重复的。

Untitled.png

上述运算符的具体含义可以我们通过下面的式子来定义,其中count(x,S)count(x, S)代表xxSS中出现的次数:

Untitled 1.png

物化视图表达式

对于一个物化视图VV和事务tt,我们是要求得如下的等式:

pre(t,V)=(V˙(t,V))(t,V)pre(t, V) = (V \dot{-} \triangledown (t, V)) \uplus \triangle (t, V)

其中 pre(t,V)pre(t, V)表示使用tt之前的数据库的状态计算出来的新的VV的值,其中(t,V)\triangledown (t, V)表示删除的值,(t,V)\triangle (t, V)表示增加的值。由于这样的表达式可能有很多,1中定义了2个性质:

  • weakly minimal:(t,V)˙V=weakly\ minimal: \triangledown(t, V) \dot{-} V = \empty
  • strongly minimum:(t,V)min(t,V)=strongly\ minimum: \triangledown (t, V) \min \triangle (t, V) = \empty

更新算法

在1中作者提出了change propagation equation:

Untitled 2.png

根据这个等式,1和2中作者提到了递归计算视图变更的方法:

Untitled 3.png

其中del(t,S)=S˙Sdel(t, S) = S \dot{-} \triangledown S, add(t,S)=SSadd(t, S) = S \uplus \triangle S

参考文献

  1. Griffin, Timothy, and Leonid Libkin. "Incremental maintenance of views with duplicates." Proceedings of the 1995 ACM SIGMOD international conference on Management of data. 1995.
  2. Quass, Dallan. "Maintenance expressions for views with aggregation." (1996).
  3. Colby, Latha S., et al. "Algorithms for deferred view maintenance." Proceedings of the 1996 ACM SIGMOD international conference on Management of data. 1996.