SlideShare a Scribd company logo
1 of 20
Materialized Views
Acknowledgement to Author: Willie
Albino
2
Materialized Views – Agenda
 What is a Materialized View?
– Advantages and Disadvantages
 How Materialized Views Work
– Parameter Settings, Privileges, Query Rewrite
 Creating Materialized Views
– Syntax, Refresh Modes/Options, Build Methods
– Examples
3
What is a Materialized View?
 A database object that stores the results of a query
– Marries the query rewrite features found in Oracle
Discoverer with the data refresh capabilities of snapshots
 Features/Capabilities
– Can be partitioned and indexed
– Can be queried directly
– Can have DML applied against it
– Several refresh options are available
– Best in read-intensive environments
4
Ordinary views vs. materialized views
 Ordinary views
– Virtual table
– Named select statement
 Part of the SQL standard
 Syntax
– CREATE VIEW viewName
AS selectStatement
 Physical table
– Replication of master data at a
single point in time
 Not part of the SQL standard
 Syntax
– CREATE MATERIALIZED
VIEW viewName AS
selectStatement
5
Why use materialized views?
 Replicate data to non-master sites
– To save network traffic when data is used in transactions
 Cache expensive queries
– Expensive in terms of time or memory
– Example: Sum, average or other calculations on large
amounts of data
6
Advantages and Disadvantages
 Advantages
– Useful for summarizing, pre-computing, replicating and
distributing data
– Faster access for expensive and complex joins
– Transparent to end-users
 MVs can be added/dropped without invalidating coded SQL
 Disadvantages
– Performance costs of maintaining the views
– Storage costs of maintaining the views
7
Database Parameter Settings
 System or session settings
– query_rewrite_enabled={true|false}
 Can be set for a session using
– alter session set query_rewrite_enabled=true;
 Privileges which must be granted to users directly
– QUERY_REWRITE - for MV using objects in own schema
– GLOBAL_QUERY_REWRITE - for objects in other schemas
8
Syntax For Materialized Views
CREATE MATERIALIZED VIEW <name>
TABLESPACE <tbs name> {<storage parameters>}
<build option>
REFRESH <refresh option> <refresh mode>
[ENABLE|DISABLE] QUERY REWRITE
AS
SELECT <select clause>;
The <build option> determines when MV is built
– BUILD IMMEDIATE: view is built at creation time
– BUILD DEFFERED: view is built at a later time
9
 Refresh Options
– COMPLETE – totally refreshes the view
 Can be done at any time; can be time consuming
– FAST – incrementally applies data changes
 A materialized view log is required on each detail table
 Data changes are recorded in MV logs or direct loader logs
 Many other requirements must be met for fast refreshes
– FORCE – Try a FAST refresh, if not possible make COMPLETE
 The default refresh option
Materialized View Refresh Options
10
Materialized View Refresh Modes
 Refresh Modes
– ON COMMIT – refreshes occur whenever a commit is
performed on one of the view’s underlying detail table(s)
 Available only with single table aggregate or join based views
 Keeps view data transactionally accurate
 Need to check alert log for view creation errors
– ON DEMAND – refreshes are initiated manually using one of
the procedures in the DBMS_MVIEW package
 Can be used with all types of materialized views
 Manual Refresh Procedures
– DBMS_MVIEW.REFRESH(<mv_name>, <refresh_option>)
– DBMS_MVIEW.REFRESH_ALL_MVIEWS()
– START WITH [NEXT] <date> - refreshes start at a specified
date/time and continue at regular intervals
11
Materialized View Example
CREATE MATERIALIZED VIEW items_summary_mv
REFRESH FORCE AS
SELECT a.PRD_ID, a.SITE_ID, a.TYPE_CODE, a.CATEG_ID,
sum(a.GMS) GMS,
sum(a.NET_REV) NET_REV,
sum(a.BOLD_FEE) BOLD_FEE,
sum(a.BIN_PRICE) BIN_PRICE,
sum(a.GLRY_FEE) GLRY_FEE,
sum(a.QTY_SOLD) QTY_SOLD,
count(a.ITEM_ID) UNITS
FROM items a
GROUP BY a.PRD_ID, a.SITE_ID, a.TYPE_CODE, a.CATEG_ID;
ANALYZE TABLE item_summary_mv COMPUTE STATISTICS;
12
Materialized View Example (cont’d)
-- Query to test impact of materialized view
select categ_id, site_id,
sum(net_rev),
sum(bold_fee),
count(item_id)
from items
where prd_id in ('2000M05','2000M06','2001M07','2001M08')
and site_id in (0,1)
and categ_id in (2,4,6,8,1,22)
group by categ_id, site_id
save mv_example.sql
13
Materialized View Example (cont’d)
SQL> ALTER SESSION SET QUERY_REWRITE_ENABLED=FALSE;
SQL> @mv_example.sql
CATEG_ID SITE_ID SUM(NET_REV) SUM(BOLD_FEE) COUNT(ITEM_ID)
-------- ------- ------------ ------------- --------------
1 0 -2.35 0 1
22 0 -42120.87 -306 28085
Elapsed: 01:32:17.93
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=HINT: FIRST_ROWS (Cost=360829 Card=6 Bytes=120)
1 0 SORT (GROUP BY) (Cost=360829 Card=6 Bytes=120)
2 1 PARTITION RANGE (INLIST
3 2 TABLE ACCESS (FULL) OF ‘ITEMS' (Cost=360077
Card=375154 Bytes=7503080)
14
Materialized View Example (cont’d)
SQL> ALTER SESSION SET QUERY_REWRITE_ENABLED=TRUE;
SQL> @mv_example.sql
CATEG_ID SITE_ID SUM(NET_REV) SUM(BOLD_FEE) COUNT(ITEM_ID)
-------- ------- ------------ ------------- --------------
1 0 -2.35 0 1
22 0 -42120.87 -306 28085
Elapsed: 00:01:40.47
Execution Plan
----------------------------------------------------------------------------------------------
0 SELECT STATEMENT Optimizer=HINT: FIRST_ROWS (Cost=3749 Card=12 Bytes=276)
1 0 SORT (GROUP BY) (Cost=3749 Card=12 Bytes=276)
2 1 PARTITION RANGE (INLIST)
3 2 TABLE ACCESS (FULL) OF ‘ITEMS_SUMMARY_MV'
(Cost=3723 Card=7331 Bytes=168613)
15
Example of FAST REFRESH MV
CREATE MATERIALIZED VIEW LOG ON ITEMS
TABLESPACE MV_LOGS STORAGE(INITIAL 10M NEXT 10M) WITH ROWID;
CREATE MATERIALIZED VIEW LOG ON CUSTOMERS
TABLESPACE MV_LOGS STORAGE(INITIAL 1M NEXT 1M) WITH ROWID;
CREATE MATERIALIZED VIEW cust_activity
BUILD IMMEDIATE
REFRESH FAST ON COMMIT
AS
SELECT u.ROWID cust_rowid, l.ROWID item_rowid,
u.cust_id, u.custname, u.email,
l.categ_id, l.site_id, sum(gms), sum(net_rev_fee)
FROM customers u, items l
WHERE u.cust_id = l.seller_id
GROUP BY u.cust_id, u.custname, u.email, l.categ_id, l.site_id;
16
Getting Information About an MV
Getting information about the key columns of a materialized view:
SELECT POSITION_IN_SELECT POSITION,
CONTAINER_COLUMN COLUMN,
DETAILOBJ_OWNER OWNER,
DETAILOBJ_NAME SOURCE,
DETAILOBJ_ALIAS ALIAS,
DETAILOBJ_TYPE TYPE,
DETAILOBJ_COLUMN SRC_COLUMN
FROM USER_MVIEW_KEYS
WHERE MVIEW_NAME=‘ITEMS_SUMMARY_MV’;
POS COLUMN OWNER SOURCE ALIAS TYPE SRC_COLUMN
--- ---------- ----- -------- ----- ------ -----------
1 PRD_ID TAZ ITEMS A TABLE PRD_ID
2 SITE_ID TAZ ITEMS A TABLE SITE_ID
3 TYPE_CODE TAZ ITEMS A TABLE TYPE_CODE
4 CATEG_ID TAZ ITEMS A TABLE CATEG_ID
17
Getting Information About an MV
Getting information about the aggregate columns of a materialized
view:
SELECT POSITION_IN_SELECT POSITION,
CONTAINER_COLUMN COLUMN,
AGG_FUNCTION
FROM USER_MVIEW_AGGREGATES
WHERE MVIEW_NAME=‘ITEMS_SUMMARY_MV’;
POSITION COLUMN AGG_FUNCTION
-------- ----------------- ------------
6 GMS SUM
7 NET_REV SUM
: : :
11 QTY_SOLD SUM
12 UNITS COUNT
Willie Albino May 15, 2003
18
Summary
 Materialized Views
– reduce system cpu/io resource requirements by pre-
calculating and storing results of intensive queries
– allow for the automatic rewriting of intensive queries
– are transparent to the application
– have storage/maintenance requirements
– can understand complex data relationships
– can be refreshed on demand or on a schedule
19
Requirements for FAST REFRESH
Requirement Joins Only Joins &
Aggregates
Single Table
Aggregates
Must be based on detail tables only X X X
Must be based on a single table X
Each table can appear only once in the FROM list X X X
Cannot contain nonrepeating expressions (ROWNUM, SYSDATE, etc) X X X
Cannot contain references to RAW or LONG RAW X X X
Cannot contain the GROUP BY clause X
The SELECT list must include the ROWIDs of all the detail tables X
Expressions can be included in the GROUP BY and SELECT clause as
long as they are the same in each
X X
Aggregates are allowed but cannot be nested X X
If SELECT clause contains AVG, it must also contain COUNT X X
If SELECT clause contains SUM, it must also contain COUNT X
If SELECT clause contains VARIANCE, it must also contain COUNT
and SUM
X X
If SELECT clause contains STDDEV, it must also contain COUNT and
SUM
X
The join predicates of the WHERE clause can included AND but not OR X
The HAVING and CONNECT BY clauses are not allowed X X X
Requirement Joins Only Joins &
Aggregates
Single Table
Aggregates
Sub-queries, inline views, or set functions such as UNION are not
allowed
X X X
A WHERE clause is not allowed X
COUNT(*) must be present X
MIN and MAX are not allowed X
Unique constraints must exist on the join columns of the inner table, if
an outer join is used
X
A materialized view log must exist that contains all column referenced in
the materialized view, and it must have been created with the LOG
NEW VALUES clause
X
A materialized view log containing ROWID must exist for each detail
table
X
Any non aggregate expressions in the SELECT and GROUP BY
clauses must be non-modified columns
X
DML allowed on detailed tables X X
Direct path data load allowed X X X
20
Rqmts For FAST REFRESH (cont’d)

More Related Content

Similar to materialized view description presentation

MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)Valeriy Kravchuk
 
PostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
PostgreSQL Performance Tables Partitioning vs. Aggregated Data TablesPostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
PostgreSQL Performance Tables Partitioning vs. Aggregated Data TablesSperasoft
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data RedactionAlex Zaballa
 
Whats New on SAP HANA SPS 11 Core Database Capabilities
Whats New on SAP HANA SPS 11 Core Database CapabilitiesWhats New on SAP HANA SPS 11 Core Database Capabilities
Whats New on SAP HANA SPS 11 Core Database CapabilitiesSAP Technology
 
Introducing ms sql_server_updated
Introducing ms sql_server_updatedIntroducing ms sql_server_updated
Introducing ms sql_server_updatedleetinhf
 
SQL Performance Solutions: Refactor Mercilessly, Index Wisely
SQL Performance Solutions: Refactor Mercilessly, Index WiselySQL Performance Solutions: Refactor Mercilessly, Index Wisely
SQL Performance Solutions: Refactor Mercilessly, Index WiselyEnkitec
 
05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptxKareemBullard1
 
WooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda BagusWooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda BagusWordCamp Indonesia
 
The Database Environment Chapter 7
The Database Environment Chapter 7The Database Environment Chapter 7
The Database Environment Chapter 7Jeanie Arnoco
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedureftz 420
 
Maria db audit plugin introduction v1.3
Maria db audit plugin introduction v1.3Maria db audit plugin introduction v1.3
Maria db audit plugin introduction v1.3YUCHENG HU
 
Understand when to use user defined functions in sql server tech-republic
Understand when to use user defined functions in sql server   tech-republicUnderstand when to use user defined functions in sql server   tech-republic
Understand when to use user defined functions in sql server tech-republicKaing Menglieng
 
Vpd Virtual Private Database By Saurabh
Vpd   Virtual Private Database By SaurabhVpd   Virtual Private Database By Saurabh
Vpd Virtual Private Database By Saurabhguestd83b546
 
Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009hugowetterberg
 
chap 7.ppt(sql).ppt
chap 7.ppt(sql).pptchap 7.ppt(sql).ppt
chap 7.ppt(sql).pptarjun431527
 

Similar to materialized view description presentation (20)

MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
 
Les11.ppt
Les11.pptLes11.ppt
Les11.ppt
 
PostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
PostgreSQL Performance Tables Partitioning vs. Aggregated Data TablesPostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
PostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data Redaction
 
Whats New on SAP HANA SPS 11 Core Database Capabilities
Whats New on SAP HANA SPS 11 Core Database CapabilitiesWhats New on SAP HANA SPS 11 Core Database Capabilities
Whats New on SAP HANA SPS 11 Core Database Capabilities
 
Introducing ms sql_server_updated
Introducing ms sql_server_updatedIntroducing ms sql_server_updated
Introducing ms sql_server_updated
 
SQL Performance Solutions: Refactor Mercilessly, Index Wisely
SQL Performance Solutions: Refactor Mercilessly, Index WiselySQL Performance Solutions: Refactor Mercilessly, Index Wisely
SQL Performance Solutions: Refactor Mercilessly, Index Wisely
 
Les10
Les10Les10
Les10
 
05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx
 
WooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda BagusWooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda Bagus
 
The Database Environment Chapter 7
The Database Environment Chapter 7The Database Environment Chapter 7
The Database Environment Chapter 7
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedure
 
Maria db audit plugin introduction v1.3
Maria db audit plugin introduction v1.3Maria db audit plugin introduction v1.3
Maria db audit plugin introduction v1.3
 
Understand when to use user defined functions in sql server tech-republic
Understand when to use user defined functions in sql server   tech-republicUnderstand when to use user defined functions in sql server   tech-republic
Understand when to use user defined functions in sql server tech-republic
 
Vpd Virtual Private Database By Saurabh
Vpd   Virtual Private Database By SaurabhVpd   Virtual Private Database By Saurabh
Vpd Virtual Private Database By Saurabh
 
2.1 view
2.1 view2.1 view
2.1 view
 
Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009
 
Chap 7
Chap 7Chap 7
Chap 7
 
chap 7.ppt(sql).ppt
chap 7.ppt(sql).pptchap 7.ppt(sql).ppt
chap 7.ppt(sql).ppt
 

Recently uploaded

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 

Recently uploaded (20)

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 

materialized view description presentation

  • 2. 2 Materialized Views – Agenda  What is a Materialized View? – Advantages and Disadvantages  How Materialized Views Work – Parameter Settings, Privileges, Query Rewrite  Creating Materialized Views – Syntax, Refresh Modes/Options, Build Methods – Examples
  • 3. 3 What is a Materialized View?  A database object that stores the results of a query – Marries the query rewrite features found in Oracle Discoverer with the data refresh capabilities of snapshots  Features/Capabilities – Can be partitioned and indexed – Can be queried directly – Can have DML applied against it – Several refresh options are available – Best in read-intensive environments
  • 4. 4 Ordinary views vs. materialized views  Ordinary views – Virtual table – Named select statement  Part of the SQL standard  Syntax – CREATE VIEW viewName AS selectStatement  Physical table – Replication of master data at a single point in time  Not part of the SQL standard  Syntax – CREATE MATERIALIZED VIEW viewName AS selectStatement
  • 5. 5 Why use materialized views?  Replicate data to non-master sites – To save network traffic when data is used in transactions  Cache expensive queries – Expensive in terms of time or memory – Example: Sum, average or other calculations on large amounts of data
  • 6. 6 Advantages and Disadvantages  Advantages – Useful for summarizing, pre-computing, replicating and distributing data – Faster access for expensive and complex joins – Transparent to end-users  MVs can be added/dropped without invalidating coded SQL  Disadvantages – Performance costs of maintaining the views – Storage costs of maintaining the views
  • 7. 7 Database Parameter Settings  System or session settings – query_rewrite_enabled={true|false}  Can be set for a session using – alter session set query_rewrite_enabled=true;  Privileges which must be granted to users directly – QUERY_REWRITE - for MV using objects in own schema – GLOBAL_QUERY_REWRITE - for objects in other schemas
  • 8. 8 Syntax For Materialized Views CREATE MATERIALIZED VIEW <name> TABLESPACE <tbs name> {<storage parameters>} <build option> REFRESH <refresh option> <refresh mode> [ENABLE|DISABLE] QUERY REWRITE AS SELECT <select clause>; The <build option> determines when MV is built – BUILD IMMEDIATE: view is built at creation time – BUILD DEFFERED: view is built at a later time
  • 9. 9  Refresh Options – COMPLETE – totally refreshes the view  Can be done at any time; can be time consuming – FAST – incrementally applies data changes  A materialized view log is required on each detail table  Data changes are recorded in MV logs or direct loader logs  Many other requirements must be met for fast refreshes – FORCE – Try a FAST refresh, if not possible make COMPLETE  The default refresh option Materialized View Refresh Options
  • 10. 10 Materialized View Refresh Modes  Refresh Modes – ON COMMIT – refreshes occur whenever a commit is performed on one of the view’s underlying detail table(s)  Available only with single table aggregate or join based views  Keeps view data transactionally accurate  Need to check alert log for view creation errors – ON DEMAND – refreshes are initiated manually using one of the procedures in the DBMS_MVIEW package  Can be used with all types of materialized views  Manual Refresh Procedures – DBMS_MVIEW.REFRESH(<mv_name>, <refresh_option>) – DBMS_MVIEW.REFRESH_ALL_MVIEWS() – START WITH [NEXT] <date> - refreshes start at a specified date/time and continue at regular intervals
  • 11. 11 Materialized View Example CREATE MATERIALIZED VIEW items_summary_mv REFRESH FORCE AS SELECT a.PRD_ID, a.SITE_ID, a.TYPE_CODE, a.CATEG_ID, sum(a.GMS) GMS, sum(a.NET_REV) NET_REV, sum(a.BOLD_FEE) BOLD_FEE, sum(a.BIN_PRICE) BIN_PRICE, sum(a.GLRY_FEE) GLRY_FEE, sum(a.QTY_SOLD) QTY_SOLD, count(a.ITEM_ID) UNITS FROM items a GROUP BY a.PRD_ID, a.SITE_ID, a.TYPE_CODE, a.CATEG_ID; ANALYZE TABLE item_summary_mv COMPUTE STATISTICS;
  • 12. 12 Materialized View Example (cont’d) -- Query to test impact of materialized view select categ_id, site_id, sum(net_rev), sum(bold_fee), count(item_id) from items where prd_id in ('2000M05','2000M06','2001M07','2001M08') and site_id in (0,1) and categ_id in (2,4,6,8,1,22) group by categ_id, site_id save mv_example.sql
  • 13. 13 Materialized View Example (cont’d) SQL> ALTER SESSION SET QUERY_REWRITE_ENABLED=FALSE; SQL> @mv_example.sql CATEG_ID SITE_ID SUM(NET_REV) SUM(BOLD_FEE) COUNT(ITEM_ID) -------- ------- ------------ ------------- -------------- 1 0 -2.35 0 1 22 0 -42120.87 -306 28085 Elapsed: 01:32:17.93 Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=HINT: FIRST_ROWS (Cost=360829 Card=6 Bytes=120) 1 0 SORT (GROUP BY) (Cost=360829 Card=6 Bytes=120) 2 1 PARTITION RANGE (INLIST 3 2 TABLE ACCESS (FULL) OF ‘ITEMS' (Cost=360077 Card=375154 Bytes=7503080)
  • 14. 14 Materialized View Example (cont’d) SQL> ALTER SESSION SET QUERY_REWRITE_ENABLED=TRUE; SQL> @mv_example.sql CATEG_ID SITE_ID SUM(NET_REV) SUM(BOLD_FEE) COUNT(ITEM_ID) -------- ------- ------------ ------------- -------------- 1 0 -2.35 0 1 22 0 -42120.87 -306 28085 Elapsed: 00:01:40.47 Execution Plan ---------------------------------------------------------------------------------------------- 0 SELECT STATEMENT Optimizer=HINT: FIRST_ROWS (Cost=3749 Card=12 Bytes=276) 1 0 SORT (GROUP BY) (Cost=3749 Card=12 Bytes=276) 2 1 PARTITION RANGE (INLIST) 3 2 TABLE ACCESS (FULL) OF ‘ITEMS_SUMMARY_MV' (Cost=3723 Card=7331 Bytes=168613)
  • 15. 15 Example of FAST REFRESH MV CREATE MATERIALIZED VIEW LOG ON ITEMS TABLESPACE MV_LOGS STORAGE(INITIAL 10M NEXT 10M) WITH ROWID; CREATE MATERIALIZED VIEW LOG ON CUSTOMERS TABLESPACE MV_LOGS STORAGE(INITIAL 1M NEXT 1M) WITH ROWID; CREATE MATERIALIZED VIEW cust_activity BUILD IMMEDIATE REFRESH FAST ON COMMIT AS SELECT u.ROWID cust_rowid, l.ROWID item_rowid, u.cust_id, u.custname, u.email, l.categ_id, l.site_id, sum(gms), sum(net_rev_fee) FROM customers u, items l WHERE u.cust_id = l.seller_id GROUP BY u.cust_id, u.custname, u.email, l.categ_id, l.site_id;
  • 16. 16 Getting Information About an MV Getting information about the key columns of a materialized view: SELECT POSITION_IN_SELECT POSITION, CONTAINER_COLUMN COLUMN, DETAILOBJ_OWNER OWNER, DETAILOBJ_NAME SOURCE, DETAILOBJ_ALIAS ALIAS, DETAILOBJ_TYPE TYPE, DETAILOBJ_COLUMN SRC_COLUMN FROM USER_MVIEW_KEYS WHERE MVIEW_NAME=‘ITEMS_SUMMARY_MV’; POS COLUMN OWNER SOURCE ALIAS TYPE SRC_COLUMN --- ---------- ----- -------- ----- ------ ----------- 1 PRD_ID TAZ ITEMS A TABLE PRD_ID 2 SITE_ID TAZ ITEMS A TABLE SITE_ID 3 TYPE_CODE TAZ ITEMS A TABLE TYPE_CODE 4 CATEG_ID TAZ ITEMS A TABLE CATEG_ID
  • 17. 17 Getting Information About an MV Getting information about the aggregate columns of a materialized view: SELECT POSITION_IN_SELECT POSITION, CONTAINER_COLUMN COLUMN, AGG_FUNCTION FROM USER_MVIEW_AGGREGATES WHERE MVIEW_NAME=‘ITEMS_SUMMARY_MV’; POSITION COLUMN AGG_FUNCTION -------- ----------------- ------------ 6 GMS SUM 7 NET_REV SUM : : : 11 QTY_SOLD SUM 12 UNITS COUNT
  • 18. Willie Albino May 15, 2003 18 Summary  Materialized Views – reduce system cpu/io resource requirements by pre- calculating and storing results of intensive queries – allow for the automatic rewriting of intensive queries – are transparent to the application – have storage/maintenance requirements – can understand complex data relationships – can be refreshed on demand or on a schedule
  • 19. 19 Requirements for FAST REFRESH Requirement Joins Only Joins & Aggregates Single Table Aggregates Must be based on detail tables only X X X Must be based on a single table X Each table can appear only once in the FROM list X X X Cannot contain nonrepeating expressions (ROWNUM, SYSDATE, etc) X X X Cannot contain references to RAW or LONG RAW X X X Cannot contain the GROUP BY clause X The SELECT list must include the ROWIDs of all the detail tables X Expressions can be included in the GROUP BY and SELECT clause as long as they are the same in each X X Aggregates are allowed but cannot be nested X X If SELECT clause contains AVG, it must also contain COUNT X X If SELECT clause contains SUM, it must also contain COUNT X If SELECT clause contains VARIANCE, it must also contain COUNT and SUM X X If SELECT clause contains STDDEV, it must also contain COUNT and SUM X The join predicates of the WHERE clause can included AND but not OR X The HAVING and CONNECT BY clauses are not allowed X X X
  • 20. Requirement Joins Only Joins & Aggregates Single Table Aggregates Sub-queries, inline views, or set functions such as UNION are not allowed X X X A WHERE clause is not allowed X COUNT(*) must be present X MIN and MAX are not allowed X Unique constraints must exist on the join columns of the inner table, if an outer join is used X A materialized view log must exist that contains all column referenced in the materialized view, and it must have been created with the LOG NEW VALUES clause X A materialized view log containing ROWID must exist for each detail table X Any non aggregate expressions in the SELECT and GROUP BY clauses must be non-modified columns X DML allowed on detailed tables X X Direct path data load allowed X X X 20 Rqmts For FAST REFRESH (cont’d)