DB2 create staging table for MQT(Materialized Query Table) 用于增量刷新

DB2 create staging table for MQT(Materialized Query Table) for incremental refresh

如何为 MQT(具体化查询 Table)创建暂存 table?

目标是使用增量刷新(而不是完全刷新)

这是 IBMi 上的 DB2

我正在关注这篇文章 https://www.ibm.com/support/knowledgecenter/en/SSEPGG_9.7.0/com.ibm.db2.luw.apdv.sample.doc/doc/clp/s-tbast-db2.html

我能够创建 MQT

当我尝试按照示例创建登台时 table 我收到错误消息

例如,

为 XXLIB.SALES 创建 MQT:

create table XXLIB.SALES as 
(select Company, Territory, SUM(Sales) 
From XXLIB.HISTORY Where Company = 1 Group by Company, Territory)
data initially deferred refresh deferred maintained by user

然后进行分期XXLIB.SALES_S

CREATE TABLE XXLIB.SALES_S FOR XXLIB.SALES PROPAGATE IMMEDIATE;

这是错误信息

SQL State: 42601 Vendor Code: -104 Message: [SQL0104] Token . was not valid. Valid tokens: . Cause . . . . . : A syntax error was detected at token .. Token . is not a valid token. A partial list of valid tokens is . This list assumes that the statement is correct up to the token. The error may be earlier in the statement, but the syntax of the statement appears to be valid up to this point. Recovery . . . : Do one or more of the following and try the request again: -- Verify the SQL statement in the area of the token .. Correct the statement. The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to the order of clauses. -- If the error token is , correct the SQL statement because it does not end with a valid clause.

Processing ended because the highlighted statement did not complete successfully

不幸的是,Db2 for IBM i 不支持 Db2 for LUW 所支持的所有 MQT 功能。

Db2 for i 缺少系统维护的 MQT 以及增量用户维护的 MQT。

您需要在 Db2 for i 上使用基础上的触发器推出您自己的解决方案 table。

您的触发器可以立即更新 MQT 或写入您自己的 "staging" table。 注意 table 仅在您的刷新过程使用它的意义上才暂存。您必须自己手动创建它,就 Db2 for i 而言,它是一个完全独立的 table。

就我个人而言,我从不为 MQT 烦恼,而是使用带有计算列的编码矢量索引 (EVI) 来满足我考虑过的所有需求。 (注意 Db2 LUW 没有 EVI)

EVI 由系统维护,因此数据始终是最新的。

CREATE ENCODED VECTOR INDEX sales_fact_location_id_evi 
ON sales_fact(sale_location_id ASC) 
INCLUDE(SUM(sale_amount_measure))

以下 IBM 文档 Accelerated analytics - faster aggregations using the IBM DB2 for i encoded vector index (EVI) technology 讨论了在其他 RDBMS 可能使用 MQT 的情况下使用 EVI。

已添加
这是一个 EVI,它将取代您尝试创建的 MQT...

CREATE ENCODED VECTOR INDEX XXLIB.SALES 
ON XXLIB.HISTORY(Company, Territory)
INCLUDE(SUM(Sales))

与 MQT 相比,EVI 的唯一缺点是您可以在查询中直接引用 MQT,而不是依赖于 DB 隐式使用它。使用 EVI,您依赖于 DB 来隐式使用它。