1 Transactions, Views, Indexes Controlling Concurrent Behavior Virtual and Materialized Views Speeding Accesses to Data This slides are from J. Ullman’s.

Slides:



Advertisements
Similar presentations
Union, Intersection, Difference (subquery) UNION (subquery) produces the union of the two relations. Similarly for INTERSECT, EXCEPT = intersection and.
Advertisements

1 More SQL Database Modification Defining a Database Schema Views.
CMPT 354 Views and Indexes Spring 2012 Instructor: Hassan Khosravi.
Notes on Chapter 8 Transactions from Chapter 6 Views and Indexes from Chapter 8.
Chapter 7 Notes on Foreign Keys Local and Global Constraints Triggers.
1 Database Systems Relations as Bags Grouping and Aggregation Database Modification.
1 Introduction to SQL Multirelation Queries Subqueries Slides are reused by the approval of Jeffrey Ullman’s.
1 More SQL Database Modification Defining a Database Schema Views Source: slides by Jeffrey Ullman.
Fall 2001Arthur Keller – CS 1808–1 Schedule Today Oct. 18 (TH) Schemas, Views. u Read Sections u Project Part 3 extended to Oct. 23 (T). Oct.
1 More SQL Defining a Database Schema Views. 2 Defining a Database Schema uA database schema comprises declarations for the relations (“tables”) of the.
Winter 2002Arthur Keller – CS 1808–1 Schedule Today: Jan. 29 (T) u Modifications, Schemas, Views. u Read Sections Assignment 3 due. Jan. 31 (TH)
CPSC-608 Database Systems Fall 2010 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #4.
1 Constraints Foreign Keys Local and Global Constraints Triggers.
Winter 2002Judy Cushing8–1 Schedule Jan. 30 (Wed) u Modifications, Schemas, Views. Read Sections This Week (Feb 4ff) u Constraints Read Sections.
1 Transactions, Views, Indexes Controlling Concurrent Behavior Virtual and Materialized Views Speeding Accesses to Data.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #4.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #3.
CPSC-608 Database Systems Fall 2008 Instructor: Jianer Chen Office: HRBB 309B Phone: Notes #4.
Winter 2002Arthur Keller – CS 1807–1 Schedule Today: Jan. 24 (TH) u Subqueries, Grouping and Aggregation. u Read Sections Project Part 2 due.
1 More SQL Extended Relational Algebra Outerjoins, Grouping/Aggregation Insert/Delete/Update.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #2.
DB Modifications Modification = insert + delete + update. Insertion of a Tuple INSERT INTO relation VALUES (list of values). Inserts the tuple = list of.
Physical Database Design Chapter 6. Physical Design and implementation 1.Translate global logical data model for target DBMS  1.1Design base relations.
Winter 2006Keller Ullman Cushing8–1 Turning in Assignments Please turn in hard copy (use only in the direst of circumstances). I am not your secretary.
Constraints on Relations Foreign Keys Local and Global Constraints Triggers Following lecture slides are modified from Jeff Ullman’s slides
Databases 1 Fourth lecture. Rest of SQL Defining a Database Schema Views Foreign Keys Local and Global Constraints Triggers 2.
Winter 2006Keller, Ullman, Cushing9–1 Constraints Commercial relational systems allow much more “fine-tuning” of constraints than do the modeling languages.
1 IT 244 Database Management System Lecture 11 More SQL Constraints &Triggers, SQL Authorization,Transactions Foreign Keys, Local and Global Constraints,
SCUHolliday - coen 1788–1 Schedule Today u Modifications, Schemas, Views. u Read Sections (except and 6.6.6) Next u Constraints. u Read.
1 Database Systems Defining Database Schema Views.
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.
Extended Operators in SQL and Relational Algebra Zaki Malik September 11, 2008.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
1 Views, Indexes Virtual and Materialized Views Speeding Accesses to Data.
Himanshu GuptaCSE 532-SQL-1 SQL. Himanshu GuptaCSE 532-SQL-2 Why SQL? SQL is a very-high-level language, in which the programmer is able to avoid specifying.
SCUHolliday - coen 1787–1 Schedule Today: u Subqueries, Grouping and Aggregation. u Read Sections Next u Modifications, Schemas, Views. u Read.
Transactions, Views, Indexes Introduction to Transactions: Controlling Concurrent Behavior Virtual and Materialized Views Indexes: Speeding Accesses to.
Chapter 8 Views and Indexes 第 8 章 视图与索引. 8.1 Virtual Views  Views:  “virtual relations”. Another class of SQL relations that do not exist physically.
Databases : SQL-Schema Definition and View 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey.
1 Constraints, Views, Indexes Foreign Keys Constraints Triggers Virtual and Materialized Views Speeding Accesses to Data.
1 Transactions, Views, Indexes Controlling Concurrent Behavior Virtual and Materialized Views Speeding Accesses to Data This slides are from J. Ullman’s.
1 Introduction to Database Systems, CS420 SQL Views and Indexes.
1 Data Modification with SQL CREATE TABLE, INSERT, DELETE, UPDATE Slides from
1 Introduction to Database Systems, CS420 SQL JOIN, Aggregate, Grouping, HAVING and DML Clauses.
CPSC-310 Database Systems
Virtual and Materialized Views Speeding Accesses to Data
Slides are reused by the approval of Jeffrey Ullman’s
Outerjoins, Grouping/Aggregation Insert/Delete/Update
Foreign Keys Local and Global Constraints Triggers
Databases : More about SQL
CPSC-310 Database Systems
Schedule Today: Next After that Subqueries, Grouping and Aggregation.
Database Design: DBS CB, 2nd Edition
CS 440 Database Management Systems
CPSC-608 Database Systems
CPSC-310 Database Systems
CPSC-310 Database Systems
2018, Fall Pusan National University Ki-Joune Li
Virtual and Materialized Views Speeding Accesses to Data
Views and Indexes Controlling Concurrent Behavior
Speeding Accesses to Data
CPSC-608 Database Systems
CPSC-608 Database Systems
More SQL Extended Relational Algebra Outerjoins, Grouping/Aggregation
CPSC-608 Database Systems
CMSC-461 Database Management Systems
Transactions, Views, Indexes
Instructor: Zhe He Department of Computer Science
Chapter 8 Views and Indexes
Presentation transcript:

1 Transactions, Views, Indexes Controlling Concurrent Behavior Virtual and Materialized Views Speeding Accesses to Data This slides are from J. Ullman’s CS145 - Introduction to Databases web site at

2 Why Transactions? uDatabase systems are normally being accessed by many users or processes at the same time. wBoth queries and modifications. uUnlike operating systems, which support interaction of processes, a DMBS needs to keep processes from troublesome interactions.

3 Views uA view is a relation defined in terms of stored tables (called base tables ) and other views. uTwo kinds: 1.Virtual = not stored in the database; just a query for constructing the relation. 2.Materialized = actually constructed and stored.

4 Declaring Views uDeclare by: CREATE [MATERIALIZED] VIEW AS ; uDefault is virtual.

5 Example: View Definition uCanDrink(drinker, beer) is a view “containing” the drinker-beer pairs such that the drinker frequents at least one bar that serves the beer: CREATE VIEW CanDrink AS SELECT drinker, beer FROM Frequents, Sells WHERE Frequents.bar = Sells.bar;

6 Example: Accessing a View uQuery a view as if it were a base table. wAlso: a limited ability to modify views if it makes sense as a modification of one underlying base table. uExample query: SELECT beer FROM CanDrink WHERE drinker = ’Sally’;

7 Triggers on Views uGenerally, it is impossible to modify a virtual view, because it doesn’t exist. uBut an INSTEAD OF trigger lets us interpret view modifications in a way that makes sense. uExample: View Synergy has (drinker, beer, bar) triples such that the bar serves the beer, the drinker frequents the bar and likes the beer.

8 Example: The View CREATE VIEW Synergy AS SELECT Likes.drinker, Likes.beer, Sells.bar FROM Likes, Sells, Frequents WHERE Likes.drinker = Frequents.drinker AND Likes.beer = Sells.beer AND Sells.bar = Frequents.bar; Natural join of Likes, Sells, and Frequents Pick one copy of each attribute

9 Interpreting a View Insertion uWe cannot insert into Synergy --- it is a virtual view. uBut we can use an INSTEAD OF trigger to turn a (drinker, beer, bar) triple into three insertions of projected pairs, one for each of Likes, Sells, and Frequents. wSells.price will have to be NULL.

10 The Trigger CREATE TRIGGER ViewTrig INSTEAD OF INSERT ON Synergy REFERENCING NEW ROW AS n FOR EACH ROW BEGIN INSERT INTO LIKES VALUES(n.drinker, n.beer); INSERT INTO SELLS(bar, beer) VALUES(n.bar, n.beer); INSERT INTO FREQUENTS VALUES(n.drinker, n.bar); END;

11 Materialized Views uProblem: each time a base table changes, the materialized view may change. wCannot afford to recompute the view with each change. uSolution: Periodic reconstruction of the materialized view, which is otherwise “out of date.”

12 Example: Axess/Class Mailing List uThe class mailing list cs145-aut0708- students is in effect a materialized view of the class enrollment in Axess. uActually updated four times/day. wYou can enroll and miss an sent out after you enroll.

13 Example: A Data Warehouse uWal-Mart stores every sale at every store in a database. uOvernight, the sales for the day are used to update a data warehouse = materialized views of the sales. uThe warehouse is used by analysts to predict trends and move goods to where they are selling best.

14 Indexes uIndex = data structure used to speed access to tuples of a relation, given values of one or more attributes. uCould be a hash table, but in a DBMS it is always a balanced search tree with giant nodes (a full disk page) called a B-tree.

15 Declaring Indexes uNo standard! uTypical syntax: CREATE INDEX BeerInd ON Beers(manf); CREATE INDEX SellInd ON Sells(bar, beer);

16 Using Indexes uGiven a value v, the index takes us to only those tuples that have v in the attribute(s) of the index. uExample: use BeerInd and SellInd to find the prices of beers manufactured by Pete’s and sold by Joe. (next slide)

17 Using Indexes --- (2) SELECT price FROM Beers, Sells WHERE manf = ’Pete’’s’ AND Beers.name = Sells.beer AND bar = ’Joe’’s Bar’; 1.Use BeerInd to get all the beers made by Pete’s. 2.Then use SellInd to get prices of those beers, with bar = ’Joe’’s Bar’

18 Database Tuning uA major problem in making a database run fast is deciding which indexes to create. uPro: An index speeds up queries that can use it. uCon: An index slows down all modifications on its relation because the index must be modified too.

19 Example: Tuning uSuppose the only things we did with our beers database was: 1.Insert new facts into a relation (10%). 2.Find the price of a given beer at a given bar (90%). uThen SellInd on Sells(bar, beer) would be wonderful, but BeerInd on Beers(manf) would be harmful.

20 Tuning Advisors uA major research thrust. wBecause hand tuning is so hard. uAn advisor gets a query load, e.g.: 1.Choose random queries from the history of queries run on the database, or 2.Designer provides a sample workload.

21 Tuning Advisors --- (2) uThe advisor generates candidate indexes and evaluates each on the workload. wFeed each sample query to the query optimizer, which assumes only this one index is available. wMeasure the improvement/degradation in the average running time of the queries.