• 详细介绍 Oracle中的Materialized Views(物化视图/快照)


    A materialized view (snapshot) is a table segment whose contents are periodically refereshed based on query (against a local or remote table)(针对的本地或者远程表)

    The simplest way to achieve replication of data between sites for against remote tables:

    materiralized views

     

    Basic Syntax

    create materialized view

    1. -- Normal
    2. CREATE MATERIALIZED VIEW view-name
    3. BUILD [IMMEDIATE | DEFERRED]
    4. REFRESH [FAST | COMPLETE | FORCE ]
    5. ON [COMMIT | DEMAND ]
    6. [[ENABLE | DISABLE] QUERY REWRITE]
    7. AS
    8. SELECT ...;
    9. -- Pre-Built
    10. CREATE MATERIALIZED VIEW view-name
    11. ON PREBUILT TABLE
    12. REFRESH [FAST | COMPLETE | FORCE ]
    13. ON [COMMIT | DEMAND ]
    14. [[ENABLE | DISABLE] QUERY REWRITE]
    15. AS
    16. SELECT ...;

    The build clause options are shown below :

    • IMMEDIATE:  mv is populated immediately.
    • DEFFERED: mv is populated on the first requested refresh.

    The following refresh type are avaliable:

    1. FAST : mv logs are not present for source tables in
    2. COMPLETE
    3. FORCE

    A fresh can be triggered :

    • ON COMMIT: data change in one of the dependent tables be committed
    • ON DEMAND: manual request or a schedule task

    The QUERY REWRITE clause tells the optimizer if the materialized view should be consider for query rewrite operations. 

    The ON PREBUILT TABLE clause tells the database to use an existing table segment, which must have the same name as the materialized view and support the same column structure as the query.

    Check Privileges

    1. [oracle@oracle-db-19c ~]$ sqlplus / as sysdba
    2. SQL*Plus: Release 19.0.0.0.0 - Production on Sun Nov 27 15:18:35 2022
    3. Version 19.3.0.0.0
    4. Copyright (c) 1982, 2019, Oracle. All rights reserved.
    5. Connected to:
    6. Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
    7. Version 19.3.0.0.0
    8. SQL> show user;
    9. USER is "SYS"
    10. SQL>
    11. SQL> ALTER SESSION SET CONTAINER=PDB1;
    12. Session altered.
    13. SQL> grant create materialized view to scott;
    14. Grant succeeded.
    15. SQL> grant create database link to scott;
    16. Grant succeeded.
    17. SQL>
    18. SQL> conn scott/tiger@PDB1
    19. Connected.
    20. SQL> show con_name;
    21. CON_NAME
    22. ------------------------------
    23. PDB1
    24. SQL> set pagesize 200
    25. SQL> set linesize 200
    26. SQL>
    27. SQL> select * from session_privs;
    28. PRIVILEGE
    29. ----------------------------------------
    30. CREATE SESSION
    31. UNLIMITED TABLESPACE
    32. CREATE TABLE
    33. CREATE CLUSTER
    34. CREATE SEQUENCE
    35. CREATE DATABASE LINK
    36. CREATE PROCEDURE
    37. CREATE TRIGGER
    38. CREATE MATERIALIZED VIEW
    39. CREATE TYPE
    40. CREATE OPERATOR
    41. CREATE INDEXTYPE
    42. SET CONTAINER
    43. 13 rows selected.
    44. SQL>

    Create DBLINK

    1. SQL> show user
    2. USER is "SYS"
    3. SQL>
    4. SQL> grant CREATE PUBLIC DATABASE LINK,DROP PUBLIC DATABASE LINK to scott;
    5. Grant succeeded.
    6. SQL> column owner for a40
    7. SQL> column object_name for a40
    8. SQL> select owner,object_name from dba_objects where object_type='DATABASE LINK';
    9. OWNER OBJECT_NAME
    10. ---------------------------------------- ----------------------------------------
    11. SYS SYS_HUB
    12. SQL> COLUMN owner FORMAT A30
    13. SQL> COLUMN db_link FORMAT A30
    14. SQL> COLUMN username FORMAT A30
    15. SQL> COLUMN host FORMAT A30
    16. SQL> select owner,db_link,username,host from dba_db_links order by owner,db_link;
    17. OWNER DB_LINK USERNAME HOST
    18. ------------------------------ ------------------------------ ------------------------------ ------------------------------
    19. SYS SYS_HUB SEEDDATA
    20. SQL> select owner,object_name from dba_objects where object_type='DATABASE LINK';
    21. OWNER OBJECT_NAME
    22. ------------------------------ ----------------------------------------
    23. SYS SYS_HUB
    24. SQL>
    25. SQL> show user;
    26. USER is "SCOTT"
    27. SQL>
    28. SQL> create public database link LINK_ORCLPDB1
    29. 2 connect to SCOTT identified by "TIGER"
    30. 3 using
    31. 4 '(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = ORCLPDB1)))';
    32. Database link created.
    33. SQL>
    34. SQL> show user
    35. USER is "SYS"
    36. SQL> select owner,object_name from dba_objects where object_type='DATABASE LINK';
    37. OWNER OBJECT_NAME
    38. ------------------------------ ----------------------------------------
    39. SYS SYS_HUB
    40. PUBLIC LINK_ORCLPDB1
    41. SQL>
    42. SQL> show user
    43. USER is "SCOTT"
    44. SQL>
    45. SQL> select * from SCOTT.emp@LINK_ORCLPDB1;
    46. EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    47. ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
    48. 7369 SMITH CLERK 7902 17-DEC-80 800 20
    49. 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
    50. 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
    51. 7566 JONES MANAGER 7839 02-APR-81 2975 20
    52. 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
    53. 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
    54. 7782 CLARK MANAGER 7839 09-JUN-81 2450 10
    55. 7788 SCOTT ANALYST 7566 19-APR-87 3000 20
    56. 7839 KING PRESIDENT 17-NOV-81 5000 10
    57. 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
    58. 7876 ADAMS CLERK 7788 23-MAY-87 1100 20
    59. 7900 JAMES CLERK 7698 03-DEC-81 950 30
    60. 7902 FORD ANALYST 7566 03-DEC-81 3000 20
    61. 7934 MILLER CLERK 7782 23-JAN-82 1300 10
    62. 14 rows selected.
    63. SQL>

    Create Materialized View

    1. SQL> show user;
    2. USER is "SCOTT"
    3. SQL>
    4. SQL> CREATE MATERIALIZED VIEW emp_mv
    5. 2 BUILD IMMEDIATE
    6. 3 REFRESH FORCE
    7. 4 ON DEMAND
    8. 5 AS
    9. 6 SELECT * FROM emp@link_orclpdb1;
    10. Materialized view created.
    11. SQL>

    Remember to gather stats after building the materialized view.

    1. SQL> BEGIN
    2. 2 DBMS_STATS.gather_table_stats(
    3. 3 ownname => 'SCOTT',
    4. 4 tabname => 'EMP_MV');
    5. 5 END;
    6. 6 /
    7. PL/SQL procedure successfully completed.
    8. SQL>

    Create Materialized View Logs

    Since a complete refresh involves truncating the materialized view segment and re-populating it using the related query, it can be quite time consuming and involve a considerable amount of network traffic when performed against a remote table. To reduce the replication costs, materialized view logs can be created to capture all changes to the base table since the last refresh. This information allows a fast refresh, which only needs to apply the changes rather than a complete refresh of the materialized view.

    To take advantage of the of the fast refresh, connect to the master instance and create the materialized view log.

    Code:

    1. CREATE MATERIALIZED VIEW LOG ON SCOTT.EMP
    2. TABLESPACE users
    3. WITH PRIMARY KEY
    4. INCLUDING NEW VALUES;

     Options:

    1. [oracle@MaxwellDBA ~]$ sqlplus SCOTT/TIGER@ORCLPDB1
    2. SQL*Plus: Release 19.0.0.0.0 - Production on Sun Nov 27 16:14:53 2022
    3. Version 19.3.0.0.0
    4. Copyright (c) 1982, 2019, Oracle. All rights reserved.
    5. Last Successful login time: Fri Nov 18 2022 19:37:15 +08:00
    6. Connected to:
    7. Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
    8. Version 19.3.0.0.0
    9. scott@orclpdb1:orclcdb> show user
    10. USER is "SCOTT"
    11. scott@orclpdb1:orclcdb> CREATE MATERIALIZED VIEW LOG ON SCOTT.EMP
    12. 2 TABLESPACE users
    13. WITH PRIMARY KEY
    14. 4 INCLUDING NEW VALUES;
    15. Materialized view log created.
    16. scott@orclpdb1:orclcdb>

    Refresh Materialized Views

    If a materialized view is configured to refresh on commit, you should never need to manually refresh it, unless a rebuild is necessary. Remember, refreshing on commit is a very intensive operation for volatile base tables. It makes sense to use fast refreshes where possible.

    For on demand refreshes, you can choose to manually refresh the materialized view or refresh it as part of a refresh group.

    The following code creates a refresh group defined to refresh every minute and assigns a materialized view to it.

    Code :

    1. BEGIN
    2. DBMS_REFRESH.make(
    3. name => 'SCOTT.MINUTE_REFRESH',
    4. list => '',
    5. next_date => SYSDATE,
    6. interval => '/*1:Mins*/ SYSDATE + 1/(60*24)',
    7. implicit_destroy => FALSE,
    8. lax => FALSE,
    9. job => 0,
    10. rollback_seg => NULL,
    11. push_deferred_rpc => TRUE,
    12. refresh_after_errors => TRUE,
    13. purge_option => NULL,
    14. parallelism => NULL,
    15. heap_size => NULL);
    16. END;
    17. /
    18. BEGIN
    19. DBMS_REFRESH.add(
    20. name => 'SCOTT.MINUTE_REFRESH',
    21. list => 'SCOTT.EMP_MV',
    22. lax => TRUE);
    23. END;
    24. /

    Options:

    1. [oracle@oracle-db-19c ~]$ sqlplus scott/tiger@PDB1
    2. SQL*Plus: Release 19.0.0.0.0 - Production on Sun Nov 27 16:56:15 2022
    3. Version 19.3.0.0.0
    4. Copyright (c) 1982, 2019, Oracle. All rights reserved.
    5. Last Successful login time: Sun Nov 27 2022 16:50:40 +08:00
    6. Connected to:
    7. Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
    8. Version 19.3.0.0.0
    9. SQL>
    10. SQL> BEGIN
    11. 2 DBMS_REFRESH.make(
    12. 3 name => 'SCOTT.MINUTE_REFRESH',
    13. 4 list => '',
    14. 5 next_date => SYSDATE,
    15. 6 interval => '/*1:Mins*/ SYSDATE + 1/(60*24)',
    16. 7 implicit_destroy => FALSE,
    17. 8 lax => FALSE,
    18. 9 job => 0,
    19. 10 rollback_seg => NULL,
    20. 11 push_deferred_rpc => TRUE,
    21. 12 refresh_after_errors => TRUE,
    22. 13 purge_option => NULL,
    23. 14 parallelism => NULL,
    24. 15 heap_size => NULL);
    25. 16 END;
    26. 17 /
    27. PL/SQL procedure successfully completed.
    28. SQL> BEGIN
    29. 2 DBMS_REFRESH.add(
    30. 3 name => 'SCOTT.MINUTE_REFRESH',
    31. 4 list => 'SCOTT.EMP_MV',
    32. 5 lax => TRUE);
    33. 6 END;
    34. 7 /
    35. PL/SQL procedure successfully completed.
    36. SQL>

    Information about refresh groups and the materialize views in a refresh group can be queried from the DBA_RGROUP and DBA_RCHILD views respectively.

    1. SQL> column owner for a20
    2. SQL> column name for a20
    3. SQL> column ROLLBACK_SEG for a20
    4. SQL> column JOB_NAME for a20
    5. SQL> select * from dba_rgroup;
    6. REFGROUP OWNER NAME I P R ROLLBACK_SEG JOB PURGE_OPTION PARALLELISM HEAP_SIZE JOB_NAME
    7. ---------- -------------------- -------------------- - - - -------------------- ---------- ------------ ----------- ---------- --------------------
    8. 5 SCOTT MINUTE_REFRESH N Y Y 0 MV_RF$J_0_S_130
    9. SQL> desc dba_rchild;
    10. Name Null? Type
    11. ----------------------------------------------------------------------------------------------------------------- -------- ----------------------------------------------------------------------------
    12. REFGROUP NUMBER
    13. OWNER NOT NULL VARCHAR2(128)
    14. NAME NOT NULL VARCHAR2(128)
    15. TYPE# VARCHAR2(128)
    16. SQL> column owner for a20
    17. SQL> column name for a20
    18. SQL> column REFGROUP for a20
    19. SQL> column TYPE for a20
    20. SQL> select * from dba_rchild;
    21. REFGROUP OWNER NAME TYPE#
    22. ---------- -------------------- -------------------- --------------------------------------------------------------------------------------------------------------------------------
    23. ########## SCOTT EMP_MV SNAPSHOT
    24. SQL> column REFGROUP default
    25. SQL> select * from dba_rchild;
    26. REFGROUP OWNER NAME TYPE#
    27. ---------- -------------------- -------------------- --------------------------------------------------------------------------------------------------------------------------------
    28. 5 SCOTT EMP_MV SNAPSHOT
    29. SQL>

    befor 1 minutes & after 1 minutes;

    1. SQL> select * from emp_mv;
    2. EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    3. ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
    4. 7369 SMITH CLERK 7902 17-DEC-80 800 20
    5. 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
    6. 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
    7. 7566 JONES MANAGER 7839 02-APR-81 2975 20
    8. 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
    9. 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
    10. 7782 CLARK MANAGER 7839 09-JUN-81 2450 10
    11. 7788 SCOTT ANALYST 7566 19-APR-87 3000 20
    12. 7839 KING PRESIDENT 17-NOV-81 5000 10
    13. 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
    14. 7876 ADAMS CLERK 7788 23-MAY-87 1100 20
    15. 7900 JAMES CLERK 7698 03-DEC-81 950 30
    16. 7902 FORD ANALYST 7566 03-DEC-81 3000 20
    17. 7934 MILLER CLERK 7782 23-JAN-82 1300 10
    18. 14 rows selected.
    19. SQL> select * from emp_mv;
    20. EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    21. ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
    22. 7369 SMITH CLERK 7902 17-DEC-80 400 20
    23. 7499 ALLEN SALESMAN 7698 20-FEB-81 1200 300 30
    24. 7521 WARD SALESMAN 7698 22-FEB-81 850 500 30
    25. 7566 JONES MANAGER 7839 02-APR-81 2575 20
    26. 7654 MARTIN SALESMAN 7698 28-SEP-81 850 1400 30
    27. 7698 BLAKE MANAGER 7839 01-MAY-81 2450 30
    28. 7782 CLARK MANAGER 7839 09-JUN-81 2050 10
    29. 7788 SCOTT ANALYST 7566 19-APR-87 2600 20
    30. 7839 KING PRESIDENT 17-NOV-81 4600 10
    31. 7844 TURNER SALESMAN 7698 08-SEP-81 1100 0 30
    32. 7876 ADAMS CLERK 7788 23-MAY-87 700 20
    33. 7900 JAMES CLERK 7698 03-DEC-81 550 30
    34. 7902 FORD ANALYST 7566 03-DEC-81 2600 20
    35. 7934 MILLER CLERK 7782 23-JAN-82 900 10
    36. 14 rows selected.
    37. SQL>
    38. SQL>

    A materialized view can be manually refreshed using the DBMS_MVIEW package.

    Code:

    EXEC DBMS_MVIEW.refresh('EMP_MV');

    Options:

    1. SQL> select * from emp_mv;
    2. EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    3. ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
    4. 7369 SMITH CLERK 7902 17-DEC-80 800 20
    5. 7782 CLARK MANAGER 7839 09-JUN-81 2450 10
    6. 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
    7. 7788 SCOTT ANALYST 7566 19-APR-87 3000 20
    8. 7876 ADAMS CLERK 7788 23-MAY-87 1100 20
    9. 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
    10. 7566 JONES MANAGER 7839 02-APR-81 2975 20
    11. 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
    12. 7934 MILLER CLERK 7782 23-JAN-82 1300 10
    13. 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
    14. 7839 KING PRESIDENT 17-NOV-81 5000 10
    15. 7902 FORD ANALYST 7566 03-DEC-81 3000 20
    16. 7900 JAMES CLERK 7698 03-DEC-81 950 30
    17. 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
    18. 14 rows selected.
    19. SQL>
    20. SQL> EXEC DBMS_MVIEW.refresh('EMP_MV');
    21. PL/SQL procedure successfully completed.
    22. SQL> select * from emp_mv;
    23. EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    24. ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
    25. 7782 CLARK MANAGER 7839 09-JUN-81 2350 10
    26. 7499 ALLEN SALESMAN 7698 20-FEB-81 1500 300 30
    27. 7521 WARD SALESMAN 7698 22-FEB-81 1150 500 30
    28. 7788 SCOTT ANALYST 7566 19-APR-87 2900 20
    29. 7876 ADAMS CLERK 7788 23-MAY-87 1000 20
    30. 7934 MILLER CLERK 7782 23-JAN-82 1200 10
    31. 7654 MARTIN SALESMAN 7698 28-SEP-81 1150 1400 30
    32. 7902 FORD ANALYST 7566 03-DEC-81 2900 20
    33. 7839 KING PRESIDENT 17-NOV-81 4900 10
    34. 7369 SMITH CLERK 7902 17-DEC-80 700 20
    35. 7566 JONES MANAGER 7839 02-APR-81 2875 20
    36. 7844 TURNER SALESMAN 7698 08-SEP-81 1400 0 30
    37. 7698 BLAKE MANAGER 7839 01-MAY-81 2750 30
    38. 7900 JAMES CLERK 7698 03-DEC-81 850 30
    39. 14 rows selected.
    40. SQL> show user;
    41. USER is "SCOTT"
    42. SQL>

    Cleaning Up

    code:

    1. sqlplus scott/tiger@PDB1
    2. DROP MATERIALIZED VIEW emp_mv;
    3. DROP PUBLIC DATABASE LINK LINK_ORCLPDB1;
    4. BEGIN
    5. DBMS_REFRESH.destroy(name=>'SCOTT.MINUTE_REFRESH');
    6. END;
    7. /
    8. sqlplus SCOTT/TIGER@ORCLPDB1
    9. DROP MATERIALIZED VIEW LOG ON SCOTT.EMP;

    options:

    1. [oracle@oracle-db-19c ~]$ sqlplus scott/tiger@PDB1
    2. SQL*Plus: Release 19.0.0.0.0 - Production on Sun Nov 27 17:27:17 2022
    3. Version 19.3.0.0.0
    4. Copyright (c) 1982, 2019, Oracle. All rights reserved.
    5. Last Successful login time: Sun Nov 27 2022 17:07:11 +08:00
    6. Connected to:
    7. Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
    8. Version 19.3.0.0.0
    9. SQL> DROP MATERIALIZED VIEW emp_mv;
    10. Materialized view dropped.
    11. SQL>
    12. SQL> DROP PUBLIC DATABASE LINK LINK_ORCLPDB1;
    13. Database link dropped.
    14. SQL> BEGIN
    15. 2 DBMS_REFRESH.destroy(name=>'SCOTT.MINUTE_REFRESH');
    16. 3 END;
    17. 4 /
    18. PL/SQL procedure successfully completed.
    19. SQL>
    20. [oracle@MaxwellDBA ~]$
    21. [oracle@MaxwellDBA ~]$ sqlplus SCOTT/TIGER@ORCLPDB1;
    22. SQL*Plus: Release 19.0.0.0.0 - Production on Sun Nov 27 17:30:30 2022
    23. Version 19.3.0.0.0
    24. Copyright (c) 1982, 2019, Oracle. All rights reserved.
    25. Last Successful login time: Sun Nov 27 2022 17:27:27 +08:00
    26. Connected to:
    27. Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
    28. Version 19.3.0.0.0
    29. scott@orclpdb1:orclcdb>
    30. scott@orclpdb1:orclcdb> DROP MATERIALIZED VIEW LOG ON SCOTT.EMP;
    31. Materialized view log dropped.
    32. scott@orclpdb1:orclcdb>

    Aggregations and Transformations

    Materialized views can be used to improve the performance of a variety of queries, including those performing aggregations and transformations of the data. This allows the work to be done once and used repeatedly by multiple sessions, reducing the total load on the server.

    The following query does an aggregation of the data in the EMP table.

    Code:

    1. show user;
    2. set autotrace trace explain
    3. select deptno,sum(sal)
    4. from emp
    5. group by deptno;

    Options:

    1. SQL> show user;
    2. USER is "SCOTT"
    3. SQL>
    4. SQL> set autotrace trace explain
    5. SQL>
    6. SQL> select deptno,sum(sal)
    7. 2 from emp
    8. 3 group by deptno;
    9. Execution Plan
    10. ----------------------------------------------------------
    11. Plan hash value: 4067220884
    12. ---------------------------------------------------------------------------
    13. | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    14. ---------------------------------------------------------------------------
    15. | 0 | SELECT STATEMENT | | 3 | 21 | 4 (25)| 00:00:01 |
    16. | 1 | HASH GROUP BY | | 3 | 21 | 4 (25)| 00:00:01 |
    17. | 2 | TABLE ACCESS FULL| EMP | 14 | 98 | 3 (0)| 00:00:01 |
    18. ---------------------------------------------------------------------------
    19. SQL>

    Create a materialized view to perform the aggregation in advance, making sure you specify the ENABLE QUERY REWRITE clause.

    1. SQL> show user;
    2. USER is "SCOTT"
    3. SQL> CREATE MATERIALIZED VIEW emp_aggr_mv
    4. 2 BUILD IMMEDIATE
    5. 3 REFRESH FORCE
    6. 4 ON DEMAND
    7. 5 ENABLE QUERY REWRITE
    8. 6 AS
    9. 7 SELECT deptno, SUM(sal) AS sal_by_dept
    10. 8 FROM emp
    11. 9 GROUP BY deptno;
    12. Materialized view created.
    13. SQL> EXEC DBMS_STATS.gather_table_stats(USER, 'EMP_AGGR_MV');
    14. PL/SQL procedure successfully completed.
    15. SQL>

    The same query is now rewritten to take advantage of the pre-aggregated data in the materialized view, instead of the session doing the work for itself.


    Code:

    1. --ALTER SESSION SET QUERY_REWRITE_INTEGRITY = TRUSTED;
    2. --ALTER SESSION SET QUERY_REWRITE_ENABLED = TRUE;
    3. SET AUTOTRACE TRACE EXPLAIN
    4. SELECT deptno, SUM(sal)
    5. FROM emp
    6. GROUP BY deptno;

    Options:

    1. SQL> set pagesize 500
    2. SQL> set linesize 500
    3. SQL> SET AUTOTRACE TRACE EXPLAIN
    4. SQL> SELECT deptno, SUM(sal)
    5. 2 FROM emp
    6. 3 GROUP BY deptno;
    7. Execution Plan
    8. ----------------------------------------------------------
    9. Plan hash value: 2456459487
    10. --------------------------------------------------------------------------------------------
    11. | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    12. --------------------------------------------------------------------------------------------
    13. | 0 | SELECT STATEMENT | | 3 | 21 | 3 (0)| 00:00:01 |
    14. | 1 | MAT_VIEW REWRITE ACCESS FULL| EMP_AGGR_MV | 3 | 21 | 3 (0)| 00:00:01 |
    15. --------------------------------------------------------------------------------------------
    16. SQL>
  • 相关阅读:
    GM8775C :是 DSI 转双通道 LVDS发送器
    LLaMA-Adapter源码解析
    练[SUCTF 2019]CheckIn
    ARM接口编程—Interrupt(exynos 4412平台)
    Chrome获取RequestId
    LeetCode 每日一题 2024/4/15-2024/4/21
    《机器人学一(Robotics(1))》_台大林沛群 第 4 周【机械臂 逆运动学】 Quiz 4
    PID的调节
    Java之线程的详细解析二
    单细胞分析+实验验证,多重buff加身,学会你也能发7分+。
  • 原文地址:https://blog.csdn.net/u011868279/article/details/128064123