zoukankan      html  css  js  c++  java
  • [bbk3201] 第64集 Chapter 16Using Materialized Views 00

    Objectives

    After completing this lesson,you should be able to do the following:

    • Create materialized views
    • Refresh materialized views
    • Create nested materialized views
    • Create UNION ALL materialized views
    • Explain the use of query rewrites
    • Enable and control query rewrites

    Materialized Views

    • Instantiations of a SQL query
    • May be used for query rewrites
    • Refresh types:
      • -Complete or Fast
      • -Force or Never
    • Refresh modes:
      • -Manual
      • -Automated(synchronous or asynchronous)

    Creating Materialized Views

    DROP MATERIALIZED VIEW depart_sal_sum;
    
    CREATE MATERIALIZED VIEW depart_sal_sum
    AS
    SELECT d.department_name,SUM(e.salary)
    FROM hr.departments d,hr.employees e
    WHERE d.department_id = e.department_id
    GROUP BY d.department_name;
    
    SELECT * FROM depart_sal_sum;

    Refreshing MVs

    • The required parameters are:
    • A list of materialized views to refresh
    • The refresh method:F-Fast,?-Force,C-Complete
    • Set push_deferred_rpc to True,if using updatable materialized views 
    • Refresh after errors
      • -True:Allows the process to continue after an error

    -False:Refresh will stop with errors(default value)

    • Automatic refresh
      • -True:All refreshes are done in one transaction
      • -False:Each refresh is a separate transaction
    示例脚本
    DROP TABLE t;
    
    CREATE TABLE t(key int primary key,val varchar2(5));
    INSERT INTO t VALUES(1,'a');
    INSERT INTO t VALUES(2,'b');
    INSERT INTO t VALUES(3,'c');
    INSERT INTO t VALUES(4,'d');
    INSERT INTO t VALUES(5,'e');
    
    COMMIT;
    
    CREATE OR REPLACE VIEW v AS SELECT * FROM t;
    
    SELECT rowid , a.* FROM v a;
    
    DROP MATERIALIZED VIEW mv;
    
    CREATE MATERIALIZED VIEW mv AS SELECT * FROM t;
    
    SELECT rowid , b.* FROM mv b;
    手工刷新
    EXEC DBMS_MVIEW.REFRESH('MV','C');

    MV:Manual Refreshing

    • Refresh specific materialized views:
    dbms_mview.refresh('CUST_SALES',parallelism => 10);--刷新materialized view,设置parallelism参数,增加处理的并行度. 
    • Refresh materialized views based on one or more base tables:
    dbms_mview.refresh_dependent('SALES');--将所有与基表SALES相关的materialized view全部进行刷新.
    • Refresh all materialized views that are due to be refreshed:
    dbms_mview.refresh_all_mviews;
  • 相关阅读:
    模拟测试20190815(已更新)
    [JLOI2015]管道连接
    [BJWC2018]最长上升子序列
    [CQOI2012]局部极小值
    [HNOI2010]Bus 公交线路
    [BZOJ4903/CTSC2017]吉夫特
    [BZOJ3717/PA2014]Pakowanie
    [NOI2015]寿司晚宴
    [BZOJ4145/AMPPZ2014]The Prices
    [Usaco2013 Nov]No Change
  • 原文地址:https://www.cnblogs.com/arcer/p/3053999.html
Copyright © 2011-2022 走看看