1. Trang chủ
  2. » Công Nghệ Thông Tin

Using Materialized Views potx

18 332 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 18
Dung lượng 265 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

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 mater

Trang 1

Using Materialized Views

Trang 2

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

Trang 3

Materialized Views

Instantiations of a SQL query

May be used for query rewrites

Refresh types:

Complete or FastForce or Never

Refresh modes:

ManualAutomated (synchronous or asynchronous)

Trang 4

Creating Materialized Views

SQL> CREATE MATERIALIZED VIEW

2 depart_sal_sum AS

3 SELECT d.department_name, SUM(e.salary)

4 FROM hr.departments d, hr.employees e

5 WHERE d.department_id = e.department_id

6 GROUP BY d.department_name;

Trang 5

Refreshing Materialized Views

SQL> EXEC dbms_mview.refresh ('SALES_MV',

2 'F', '', TRUE, FALSE, 0,0,0, FALSE);

The required parameters are:

A comma-delimited list of materialized views to

refresh

The refresh method: F-Fast, ?-Force, C-Complete

Refresh after errors

True: allows the process to continue after an errorFalse: refresh will stop with errors (default value)

For warehouse refresh, set them to False, 0,0,0.

Atomic refresh

True: All refreshes are done in one transactionFalse: Each refresh is a separate transaction

Trang 6

Materialized Views: Manual Refreshing

Refresh specific materialized views:

Refresh materialized views based on one or more

base tables:

Refresh all materialized views that are due to be

refreshed:

dbms_mview.refresh

(’CUST_SALES’, parallelism => 10);

dbms_mview.refresh_dependent (’SALES’);

dbms_mview.refresh_all_mviews;

Trang 7

Nested Materialized Views

TOTAL_SALES

PROD_MV SALES_CUST_MV Level 1

Level 0 Level 2

Trang 8

Nested Materialized View Example

Trang 9

Union All Materialized Views

Trang 10

Query Rewrite Overview

To use materialized views instead of the base

tables, a query must be rewritten.

Query rewrites are transparent and do not require

any special privileges on the materialized view.

Materialized views can be enabled or disabled for

query rewrites.

Query rewrites can:

Ignore alphabetic case

Recognize equivalent joinsCompare the defining text of a named view

Trang 11

Query Rewrites

The QUERY_REWRITE_ENABLED initialization

parameter must be set to True.

The QUERY REWRITE privilege allows users to

enable materialized views.

The Summary Advisor of the dbms_olap package

has options to use materialized views.

Trang 12

Creating a Materialized View

SQL> CREATE MATERIALIZED VIEW sales_summary

2 TABLESPACE users

3 PARALLEL (DEGREE 4)

4 BUILD IMMEDIATE

5 ENABLE QUERY REWRITE

6 AS

7 SELECT p.prod_name,

8 SUM (s.quantity_sold),

8 SUM (s.amount_sold)

9 FROM sales s, products p

10 WHERE s.prod_id = p.prod_id

11 GROUP BY p.prod_name;

Trang 13

Materialized Views and Query Rewrites: Example

SQL> SELECT p.prod_name,SUM (s.quantity_sold),

2 SUM (s.amount_sold)

3 FROM sales s, products p

4 WHERE s.prod_id = p.prod_id

5 GROUP BY p.prod_name;

SQL> select operation, object_name

2 from v$sql_plan

3 where object_name like 'SALES%';

OPERATION NAME

-

-SELECT STATEMENT

TABLE ACCESS SALES_SUMMARY

Trang 14

Enabling and Controlling

Query Rewrites

Initialization parameters:

OPTIMIZER_MODE

QUERY_REWRITE_ENABLED

QUERY_REWRITE_INTEGRITY

Dynamic and session-level parameters:

QUERY_REWRITE_ENABLED

QUERY_REWRITE_INTEGRITY

Hints: REWRITE and NOREWRITE

Dimensions

Trang 15

Disabling Query Rewrites: Example

SQL> SELECT /*+ NOREWRITE */

2 p.prod_name, SUM (s.quantity_sold),

3 SUM (s.amount_sold)

4 FROM sales s, products p

5 WHERE s.prod_id = p.prod_id

6 GROUP BY p.prod_name;

SQL> SELECT p.operation, p.object_name

2 FROM v$sql_plan p, v$sql s

3 WHERE p.address = s.address

4 AND sql_text LIKE 'SELECT /*+ NO%';

Trang 16

Union All Query Rewrite

CREATE MATERIALIZED VIEW sales_cube_mv

ENABLE QUERY REWRITE

AS

SELECT

GROUPING_ID (calendar_year,……) gid,

GROUPING (calendar_year) grp_y,

.

GROUPING (cust_city) grp_c,

FROM sales s, times t, customers c

WHERE s.time_id=t.time_id

AND s.cust_id=c.cust_id

GROUP BY

GROUPING SETS (

(calendar_year, cust_city),

(calendar_year, , cust_state_province),

Trang 17

Using the dbms_mview Package

The package contains the following procedures:

explain_mview

explain_rewrite

refresh

refresh_all_mviews

Trang 18

In this lesson, you should have learned how to do the following:

Create materialized views

Refresh materialized views

Creating nested materialized views

Create UNION ALL materialized views

Explain the use of query rewrites

Enable and control query rewrites

Ngày đăng: 15/03/2014, 17:20

TỪ KHÓA LIÊN QUAN