如果你能解决这个问题,请提前致谢。
我在Oracle 11g r2数据库上运行,我正在构建一个新的物化视图,虽然创建视图只需要大约6分钟来创建,但每天刷新它需要大约42分钟。下面刷新此代码的过程REFRESH_ACTIVE_NON_ACQU_MV,创建物化视图的代码位于底部。有什么我做错的吗?
当我使用下面的代码进行简单的刷新时,需要25分钟。
begin
EXECUTE IMMEDIATE 'ALTER SESSION ENABLE PARALLEL DML';
dbms_mview.REFRESH('ACTIVE_NON_ACQU_MV');
end;
/
但是下面的程序需要42分钟。我不明白为什么刷新比物化视图的创建需要更长的时间?以及为什么两次刷新在刷新时间方面相差很大。
PROCEDURE REFRESH_ACTIVE_NON_ACQU_MV
IS
l_method VARCHAR2(1) := 'C';
BEGIN
EXECUTE IMMEDIATE 'ALTER SESSION ENABLE PARALLEL DML';
Dbms_Mview.Refresh(LIST=>'ACTIVE_NON_ACQU_MV',
METHOD=>l_method, atomic_refresh=>FALSE, PARALLELISM=>8);
END REFRESH_ACTIVE_NON_ACQU_MV;
创建下面的物化视图的代码。
PROMPT Drop MATERIALIZED VIEW ACTIVE_NON_ACQU_MV
-- create create MATERIALIZED VIEW ACTIVE_NON_ACQU_MV
DROP MATERIALIZED VIEW ACTIVE_NON_ACQU_MV;
-- create create MATERIALIZED VIEW ACTIVE_NON_ACQU_MV
PROMPT Create MATERIALIZED VIEW ACTIVE_NON_ACQU_MV
CREATE MATERIALIZED VIEW ACTIVE_NON_ACQU_MV (SUPPLIER,
BROADCASTER,
PRODUCTION_TITLE,
PRODUCTION_NUMBER,
SERIES_TITLE,
SUPPLIED_SOURCE_IND,
THIRD_PARTY_GROUP_ID,
BRO_BROADCAST_BY_TP_SURR_ID,
STATION_ID
)
TABLESPACE PRBLK_MV_BD_A
PCTUSED 0
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
NEXT 1M
MAXSIZE UNLIMITED
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
)
NOCACHE
LOGGING
NOCOMPRESS
PARALLEL ( DEGREE DEFAULT INSTANCES DEFAULT )
BUILD IMMEDIATE
USING INDEX
TABLESPACE PRBLK_MV_BI_A
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
)
REFRESH ON DEMAND
WITH ROWID
AS
/* Formatted on Mon/06/02/2017 10:07:52 (QP5 v5.267.14150.38573) */
select x.supplier_name as supplier ,
x.broadcaster_name as broadcaster ,
ptle.title as production_title ,
x.production_number as production_number ,
stle.title as series_title ,
x.production_source as supplied_source_ind ,
x.third_party_group_id ,
x.bro_broadcast_by_tp_surr_id,
x.STATION_ID
FROM
(select usages.production_number,
usages.prod_exploitation_cre_surr_id,
usages.bro_broadcast_by_tp_surr_id,
usages.THIRD_PARTY_SURR_ID,
usages.SUPPLIER_NAME,
usages.THIRD_PARTY_GROUP_ID,
usages.STATION_ID,
usages.BROADCASTER_NAME,
prod.cre_surr_id,
prod.production_source,
prod.prod_series_cre_surr_id
from productions prod,
(SELECT --+ parallel(uh)
uh.production_number,
uh.prod_exploitation_cre_surr_id,
uh.bro_broadcast_by_tp_surr_id,
supplier_details.THIRD_PARTY_SURR_ID,
supplier_details.SUPPLIER_NAME,
supplier_details.THIRD_PARTY_GROUP_ID,
supplier_details.STATION_ID,
supplier_details.BROADCASTER_NAME,
row_number() over(partition by uh.production_number order by uh.production_number) prod_rows
FROM usage_headers uh,
(SELECT third_party.surr_id AS THIRD_PARTY_SURR_ID,
third_party.supplier_name as SUPPLIER_NAME,
third_party.supplier_group_id AS THIRD_PARTY_GROUP_ID,
third_party.dn_root_tp_surr_id AS THIRD_PARTY_ROOT_ID,
bro.station_id AS STATION_ID,
bro.dn_tp_name AS BROADCASTER_NAME
FROM broadcasters bro,
(SELECT tp.surr_id,
tp.name AS supplier_name,
tp.tp_surr_id AS supplier_group_id,
tp.dn_root_tp_surr_id
FROM third_parties tp
CONNECT BY PRIOR tp.surr_id = tp.tp_surr_id
START WITH tp.surr_id IN (SELECT surr_id FROM ETL_ACQUIRED_MASTER WHERE NVL(exclude_flag,'N') <> 'Y')) third_party
WHERE third_party.surr_id = bro.tp_surr_id) supplier_details
WHERE uh.bro_broadcast_by_tp_surr_id = supplier_details.THIRD_PARTY_SURR_ID
AND uh.production_number IS NOT NULL
AND uh.prod_exploitation_cre_surr_id IS NOT NULL
AND uh.right_type IN ('M', 'B')
AND NVL (uh.dn_uls_usage_status, '3') NOT IN ('9', '11')
AND uh.udg_surr_id IS NOT NULL
AND NOT EXISTS (SELECT 1
FROM prblk.production_usage_components puc
WHERE puc.uh_surr_id = uh.surr_id
AND PUC.DISTRIBUTION_STATUS IS NOT NULL)) usages
WHERE usages.prod_rows = 1
AND usages.prod_exploitation_cre_surr_id = prod.cre_surr_id
AND prod.production_source <> 'AP') x
LEFT OUTER JOIN titles ptle ON ( ptle.cre_surr_id = x.cre_surr_id AND ptle.tt_code = 'R')
LEFT OUTER JOIN titles stle ON ( stle.cre_surr_id = x.prod_series_cre_surr_id AND stle.tt_code = 'R');
COMMENT ON MATERIALIZED VIEW ACTIVE_NON_ACQU_MV IS 'snapshot of none acquired productions - ACTIVE_NON_ACQU_MV';
PROMPT select on 'ACTIVE_NON_ACQU_MV' to APPS_ACCESS_ROLE_BLK
GRANT SELECT ON ACTIVE_NON_ACQU_MV TO APPS_ACCESS_ROLE_BLK;
答案 0 :(得分:0)
尝试做:
exec dbms_mview.refresh('ACTIVE_NON_ACQU_MV', 'C', atomic_refresh=>false);
false的原子刷新意味着它将截断然后插入。如果使用原子刷新,它将执行事务性删除+插入(我相信默认)。 &#34;更安全&#34;但可以更长时间完成。
当然,不能保证总是花费相同的时间来完成刷新。例如,如果您有许多其他进程同时运行(竞争资源),您可能会遇到&#34;缓慢&#34;与其他运行时相比。
此外,如果其他人在长时间运行的事务中访问该快照表,则可能会阻止您尝试执行完整刷新(使用atomic_refresh =&gt; false)。因此,如果需要一段时间,可能会检查阻塞锁。