materializedviews annotated

14
Jennifer Widom Views Materialized Views

Upload: silviu7634

Post on 16-Sep-2015

13 views

Category:

Documents


2 download

DESCRIPTION

introducere intr-un curs despre ceva materie care e interesanta.

TRANSCRIPT

Introduction to Programming

ViewsMaterialized ViewsJennifer Widom1Why use views? Hide some data from some users Make some queries easier / more natural Modularity of database accessReal applications tend to use lots and lots (and lots and lots!) of views Materialized ViewsJennifer WidomWhy use (virtual) views? Hide some data from some users Make some queries easier / more natural Modularity of database accessMaterialized ViewsJennifer WidomWhy use materialized views? Hide some data from some users Make some queries easier / more natural Modularity of database access Improve query performanceMaterialized ViewsJennifer WidomVirtual views View V = ViewQuery(R1, R2, , Rn) Schema of V is schema of query result Query Q involving V, conceptually:

In reality, Q rewritten to use R1,,Rn instead of VV := ViewQuery(R1,R2,,Rn);Evaluate Q;Materialized ViewsJennifer WidomMaterialized views View V = ViewQuery(R1, R2, , Rn) Create table V with schema of query result Execute ViewQuery and put results in V Queries refer to V as if its a tableBut V could be very large Modifications to R1, R2, , Rn recompute or modify VMaterialized ViewsJennifer WidomCreate Materialized View CA-CS AsSelect C.cName, S.sNameFrom College C, Student S, Apply AWhere C.cName = A.cName And S.sID = A.sIDAnd C.state = CA And A.major = CScNamestateenrsIDsNameGPAHSsIDcNamemajordecCollegeStudentApply+ Can use CA-CS as if its a table (it is!)Materialized ViewsJennifer WidomCreate Materialized View CA-CS AsSelect C.cName, S.sNameFrom College C, Student S, Apply AWhere C.cName = A.cName And S.sID = A.sIDAnd C.state = CA And A.major = CScNamestateenrsIDsNameGPAHSsIDcNamemajordecCollegeStudentApply Modifications to base data invalidate viewMaterialized ViewsJennifer WidomCreate Materialized View CA-CS AsSelect C.cName, S.sNameFrom College C, Student S, Apply AWhere C.cName = A.cName And S.sID = A.sIDAnd C.state = CA And A.major = CS Modifications to base data invalidate viewMaterialized ViewsJennifer WidomQueries over materialized views View V = ViewQuery(R1, R2, , Rn) Create table V with schema of query result Execute ViewQuery and put results in V Queries refer to V as if its a tableModifications on materialized views? Good news: just update the stored table Bad news: base tables must stay in synch Same issues as with virtual viewsMaterialized ViewsJennifer Widom Modifications to V must also modify base tablesMaterialized ViewsJennifer WidomPicking which materialized views to create(Efficiency) benefits of a materialized view depend on: Size of data Complexity of view Number of queries using view Number of modifications affecting viewAlso incremental maintenance versus full recomputationMaterialized ViewsJennifer WidomAutomatic query rewriting to use materialized viewsMaterialized ViewsCreate Materialized View CA-Apply AsSelect sID, cName, majorFrom Apply AWhere cName In (Select cName From College Where state = CA) Select Distinct S.sID, S.GPAFrom College C, Student S, Apply AWhere C.cName = A.cName And S.sID = A.sID And S.GPA > 3.5 And C.state = CA And A.Major = CS Jennifer WidomWhy use materialized views? Hide some data from some users Make some queries easier / more natural Modularity of database access Improve query performanceMaterialized ViewsJennifer Widom