我遇到了一些我不了解物化视图刷新时间的事情,并希望有人可以解释我所缺少的内容。我在12cR1上。
当我定义具有N秒刷新间隔的物化视图时,视图会编译并且基础作业会尽职地记录间隔并且看起来具有正确的NEXT_SEC
,但视图不会继续-schedule具有定义的刷新间隔。
以下是一个例子。在这个例子中,我定义了一个每20秒刷新一次的轻量级mview。但是在监视其刷新时,通常需要30秒以上才能更新。如果Oracle不支持某些时间间隔,我希望mview编译失败,或者至少工作会被破坏,而不是悄悄地错过它的目标。
了解导致此结果的基础mview刷新机制的任何帮助都会很棒。任何关于更好地保持按计划的替代定义的建议也将受到赞赏。
由于
示例:
CREATE MATERIALIZED VIEW TIME_ONLY_MVIEW
REFRESH COMPLETE NEXT (SYSTIMESTAMP + NUMTODSINTERVAL(20, 'SECOND'))
AS
SELECT SYSTIMESTAMP AS TIME_OF_MVIEW_QUERY
FROM DUAL;
运行以下检查,我经常得到TIME_DELTA_SECONDS
大于30.我想知道为什么。
WITH QUERY_TIME AS
(SELECT SYSTIMESTAMP AS TIME_OF_THIS_QUERY
FROM DUAL)
SELECT
TO_CHAR(QUERY_TIME.TIME_OF_THIS_QUERY, 'HH24:MI:SS') TIME_OF_THIS_QUERY,
TO_CHAR(TIME_ONLY_MVIEW.TIME_OF_MVIEW_QUERY, 'HH24:MI:SS') TIME_OF_MVIEW_QUERY,
LAST_RECORDED_REFRESH.LAST_RECORDED_REFRESH_START,
LAST_RECORDED_REFRESH.LAST_RECORDED_REFRESH_END_TIME,
EXTRACT(SECOND FROM (QUERY_TIME.TIME_OF_THIS_QUERY - TIME_ONLY_MVIEW.TIME_OF_MVIEW_QUERY)) AS TIME_DELTA_SECONDS,
MVIEW_JOB.BROKEN,
MVIEW_JOB.FAILURES,
MVIEW_JOB.NEXT_SEC,
MVIEW_JOB.MVIEW_INTERVAL
FROM QUERY_TIME
CROSS JOIN TIME_ONLY_MVIEW
CROSS JOIN (SELECT
TO_CHAR(LAST_REFRESH_END_TIME, 'HH24:MI:SS') LAST_RECORDED_REFRESH_END_TIME,
TO_CHAR(LAST_REFRESH_DATE, 'HH24:MI:SS') LAST_RECORDED_REFRESH_START
FROM USER_MVIEWS
WHERE MVIEW_NAME = 'TIME_ONLY_MVIEW') LAST_RECORDED_REFRESH
CROSS JOIN (SELECT
USER_JOBS.BROKEN BROKEN,
USER_JOBS.FAILURES FAILURES,
USER_JOBS.NEXT_SEC NEXT_SEC,
USER_JOBS.INTERVAL MVIEW_INTERVAL
FROM USER_JOBS
WHERE USER_JOBS.WHAT LIKE 'dbms_refresh.refresh(%TIME_ONLY_MVIEW%);') MVIEW_JOB;
这是一个示例检查。工作永远不会中断,失败不会增加,但TIME_DELTA_SECONDS会增加到大约30秒,偶尔会达到40 +。
SQL> WITH QUERY_TIME AS
2 (SELECT SYSTIMESTAMP AS TIME_OF_THIS_QUERY
3 FROM DUAL)
4 SELECT
5 TO_CHAR(QUERY_TIME.TIME_OF_THIS_QUERY, 'HH24:MI:SS') TIME_OF_THIS_QUERY,
6 TO_CHAR(TIME_ONLY_MVIEW.TIME_OF_MVIEW_QUERY, 'HH24:MI:SS') TIME_OF_MVIEW_QUERY,
7 LAST_RECORDED_REFRESH.LAST_RECORDED_REFRESH_START,
8 LAST_RECORDED_REFRESH.LAST_RECORDED_REFRESH_END_TIME,
9 EXTRACT(SECOND FROM (QUERY_TIME.TIME_OF_THIS_QUERY - TIME_ONLY_MVIEW.TIME_OF_MVIEW_QUERY)) AS TIME_DELTA_SECONDS,
10 MVIEW_JOB.BROKEN,
11 MVIEW_JOB.FAILURES,
12 MVIEW_JOB.NEXT_SEC,
13 MVIEW_JOB.MVIEW_INTERVAL
14 FROM QUERY_TIME
15 CROSS JOIN TIME_ONLY_MVIEW
16 CROSS JOIN (SELECT
17 TO_CHAR(LAST_REFRESH_END_TIME, 'HH24:MI:SS') LAST_RECORDED_REFRESH_END_TIME,
18 TO_CHAR(LAST_REFRESH_DATE, 'HH24:MI:SS') LAST_RECORDED_REFRESH_START
19 FROM USER_MVIEWS
20 WHERE MVIEW_NAME = 'TIME_ONLY_MVIEW') LAST_RECORDED_REFRESH
21 CROSS JOIN (SELECT
22 USER_JOBS.BROKEN BROKEN,
23 USER_JOBS.FAILURES FAILURES,
24 USER_JOBS.NEXT_SEC NEXT_SEC,
25 USER_JOBS.INTERVAL MVIEW_INTERVAL
26 FROM USER_JOBS
27* WHERE USER_JOBS.WHAT LIKE 'dbms_refresh.refresh(%TIME_ONLY_MVIEW%);') MVIEW_JOB;
TIME_OF_THIS_QUERY TIME_OF_MVIEW_QUERY LAST_RECORDED_REFRESH_START LAST_RECORDED_REFRESH_END_TIME TIME_DELTA_SECONDS BROKEN FAILURES NEXT_SEC MVIEW_INTERVAL
12:09:14 12:08:44 12:08:44 12:08:44 30.197422 N 0 12:09:04 (SYSTIMESTAMP + NUMTODSINTERVAL(20, 'SECOND'))