我在DB2 9.7(尚未修复包1)中创建了一个用户维护的MQT(物化查询表)。这是主要事实表的简单分组。但我的查询并没有被重写以达到目的。
这是我尝试过的:
然后尝试确定优化器是否会使用MQT:
有关更简单的方法来判断查询是使用MQT还是接下来应该尝试使用它的任何建议?
答案 0 :(得分:3)
2件事:
1)CURRENT MAINTAINED TABLE TYPES FOR OPTIMIZATION
寄存器设置为什么?它默认为DFT_MTTB_TYPES
数据库配置参数的任何值 - 默认值为'SYSTEM' - 因此优化器会忽略您的MQT。
2)此外,您对DFT_REFRESH_AGE
和用户MQT维护的假设是错误的。 DFT_REFRESH_AGE
仍然适用 - 对于用户维护的MQT,CURRENT REFRESH AGE
寄存器必须设置为ANY才能考虑刷新延迟MQT。
答案 1 :(得分:0)
要调试问题,请在查询前添加:
EXPLAIN PLAN FOR
然后运行它,然后检索诊断消息:
SELECT EXPLAIN_TIME, DIAGNOSTIC_ID, MSG
FROM TABLE(EXPLAIN_GET_MSGS(
CAST(NULL AS VARCHAR(128)),
CAST(NULL AS TIMESTAMP),
CAST(NULL AS VARCHAR(128)),
CAST(NULL AS VARCHAR(128)),
CAST(NULL AS VARCHAR(64)),
CAST(NULL AS CHAR(1)),
CAST(NULL AS INTEGER),
CAST(NULL AS INTEGER),
'en_US'))
AS REGISTRYINFO
WHERE EXPLAIN_TIME >= (CURRENT TIMESTAMP - 1 HOUR)
ORDER BY EXPLAIN_TIME desc
;
就我而言:
EXPLAIN_TIME DIAGNOSTIC_ID MSG
------------------------- ------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2015-07-08 10:48:50.940231 1 EXP0053W The materialized query table "DB2INST1"."XFACETATTR" was not considered for query matching because the isolation level of the query is higher than the isolation level of the materialized query table.