Views Materialized Views.

Slides:



Advertisements
Similar presentations
Split Databases. What is a split database? Two databases Back-end database –Contains tables (data) only –Resides on server Front-end database –Contains.
Advertisements

CMPT 354 Views and Indexes Spring 2012 Instructor: Hassan Khosravi.
1 Lecture 11: Basic SQL, Integrity constraints
Introduction to Relational Databases Obtained from Portland State University.
Cs3431 Constraints Sections 6.1 – 6.5. cs3431 Example CREATE TABLE Student ( sNum int, sName varchar (20), prof int, CONSTRAINT pk PRIMARY KEY (snum),
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
1 Views. 2 Views A view is a "virtual table" defined using a query You can use a view as if it were a table, even though it doesn't contain data The view.
1 Views. 2 What are views good for?(1) Simplifying complex queries: we saw one example. Here is another example that allows the user to "pretend" that.
1 Views. 2 What are views good for? (1) Simplifying complex queries: We saw one example. Here is another that allows the user to "pretend" that there.
Data Warehouse View Maintenance Presented By: Katrina Salamon For CS561.
Jennifer Widom Views Defining and Using Views. Jennifer Widom Defining & Using Views Three-level vision of database Physical – Conceptual – Logical.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model Pearson Education © 2014.
Views, Indexes and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Haiman Tian 1.
Index and JDBC/JSP tutorial Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Chapter 8 Database Redesign We only discuss complex sub-queries.
View 1. Lu Chaojun, SJTU 2 View Three-level vision of DB users Virtual DB views DB Designer Logical DB relations DBA DBA Physical DB stored info.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
The Relational Model. 2 Relational Model Terminology u A relation is a table with columns and rows. –Only applies to logical structure of the database,
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 5 SQL.
Jennifer Widom Views Materialized Views. Jennifer Widom Why use views?  Hide some data from some users  Make some queries easier / more natural  Modularity.
SQL: The Query Language Part 1 R &G - Chapter 5 The important thing is not to stop questioning. Albert Einstein.
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
Chapter 4 The Relational Model Pearson Education © 2009.
1 Introduction to Database Systems, CS420 SQL Views and Indexes.
SQL: Interactive Queries (2) Prof. Weining Zhang Cs.utsa.edu.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
7.5 Using Stored-Procedure and Triggers NAME MATRIC NUM GROUP Muhammad Azwan Bin Khairul Anwar CS2305A Muhammad Faiz Bin Badrol Shah CS2305B.
Jennifer Widom Indexes. Jennifer Widom Indexes  Primary mechanism to get improved performance on a database  Persistent data structure, stored in database.
SQL (Structured Query Language)
Transactions Introduction.
Querying Relational Databases
CS 186, Fall 2006, Lecture 2 R & G, Chap. 3
6 Benefits of Using Microsoft Access Database. Microsoft Access is an efficient program that helps companies to carry out complex business processes in.
Basic SQL Lecture 6 Fall
Views Defining and Using Views.
Introduction to Relational Databases
Lecture#7: Fun with SQL (Part 2)
Referential Integrity
Views View Modifications  Introduction.
Transactions Introduction.
Indexes.
Relational Databases Relational Algebra (2)
Querying Relational Databases
CS 405G: Introduction to Database Systems
Chapter 4 The Relational Model Pearson Education © 2009.
CS 440 Database Management Systems
Relational Databases Relational Algebra (1) Select, project, join.
Authorization.
Referential Integrity
SQL: The Query Language Part 1
Views View Modifications  Introduction.
Views Automatic View Modifications.
Instructor: Mohamed Eltabakh
CMPT 354: Database System I
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Views View Modifications Using Triggers.
Topic 15 Lesson 1 – Action queries
Views 1.
Chapter 4 The Relational Model Pearson Education © 2009.
MIS2502: Data Analytics MySQL and MySQL Workbench
Introduction to Database Systems
So What are Views and Triggers anyway?
SQL-Views and External Schemas
Views Base Relation View
Chapter 8 Views and Indexes
Presentation transcript:

Views Materialized Views

Hide some data from some users Make some queries easier / more natural Materialized Views Why use views? Hide some data from some users Make some queries easier / more natural Modularity of database access Real applications tend to use lots and lots (and lots and lots!) of views

Why use (virtual) views? Hide some data from some users Materialized Views Why use (virtual) views? Hide some data from some users Make some queries easier / more natural Modularity of database access

Why use materialized views? Hide some data from some users Make some queries easier / more natural Modularity of database access Improve query performance

View V = ViewQuery(R1, R2, …, Rn) Materialized Views Virtual 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 V V := ViewQuery(R1,R2,…,Rn); Evaluate Q;

View V = ViewQuery(R1, R2, …, Rn) Materialized Views 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 it’s a table But… V could be very large Modifications to R1, R2, …, Rn  recompute or modify V

+ Can use CA-CS as if it’s a table (it is!) Materialized Views Create Materialized View CA-CS As Select C.cName, S.sName From College C, Student S, Apply A Where C.cName = A.cName And S.sID = A.sID And C.state = ‘CA’ And A.major = ‘CS’ + Can use CA-CS as if it’s a table (it is!) College Student Apply cName state enr sID sName GPA HS sID cName major dec

 Modifications to base data invalidate view Materialized Views Create Materialized View CA-CS As Select C.cName, S.sName From College C, Student S, Apply A Where C.cName = A.cName And S.sID = A.sID And C.state = ‘CA’ And A.major = ‘CS’  Modifications to base data invalidate view College Student Apply cName state enr sID sName GPA HS sID cName major dec

 Modifications to base data invalidate view Materialized Views Create Materialized View CA-CS As Select C.cName, S.sName From College C, Student S, Apply A Where C.cName = A.cName And S.sID = A.sID And C.state = ‘CA’ And A.major = ‘CS’  Modifications to base data invalidate view

Queries 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 it’s a table Modifications on materialized views? Good news: just update the stored table Bad news: base tables must stay in synch Same issues as with virtual views

Modifications to V must also modify base tables Materialized Views Modifications to V must also modify base tables

Picking 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 view Also “incremental maintenance” versus full recomputation

Automatic query rewriting to use materialized views Create Materialized View CA-Apply As Select sID, cName, major From Apply A Where cName In (Select cName From College Where state = ‘CA’) Select Distinct S.sID, S.GPA From College C, Student S, Apply A Where C.cName = A.cName And S.sID = A.sID And S.GPA > 3.5 And C.state = ‘CA’ And A.Major = ‘CS’

Why use materialized views? Hide some data from some users Make some queries easier / more natural Modularity of database access Improve query performance