



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Database Management Systems, 2 nd^ Edition. R. Ramakrishnan and J. Gehrke 1
Database Management Systems, 2 nd^ Edition. R. Ramakrishnan and J. Gehrke 2
Precomputation is essential for interactive response times. The CUBE is in fact a collection of aggregate queries, and precomputation is especially important: lots of work on what is best to precompute given a limited amount of space to store precomputed results.
Has renewed interest in view maintenance!
Database Management Systems, 2 nd^ Edition. R. Ramakrishnan and J. Gehrke 3
CREATE VIEW RegionalSales(category,sales,state) AS SELECT P.category, S.sales, L.state FROM Products P, Sales S, Locations L WHERE P.pid=S.pid AND S.locid=L.locid
SELECT R.category, R.state, SUM (R.sales) FROM RegionalSales AS R GROUP BY R.category, R.state
SELECT R.category, R.state, SUM (R.sales) FROM ( SELECT P.category, S.sales, L.state FROM Products P, Sales S, Locations L WHERE P.pid=S.pid AND S.locid=L.locid) AS R GROUP BY R.category, R.state
View
Query
Modified Query
Database Management Systems, 2 nd^ Edition. R. Ramakrishnan and J. Gehrke 4
Then, previous query can be answered by an index- only scan. SELECT R.state, SUM(R.sales) FROM RegionalSales R WHERE R.category=“Laptop” GROUP BY R.state
SELECT R.state, SUM(R.sales) FROM RegionalSales R WHERE R. state=“Wisconsin” GROUP BY R.category Index on precomputed view is great!
Index is less useful (must scan entire leaf level).
Database Management Systems, 2 nd^ Edition. R. Ramakrishnan and J. Gehrke 5
Provides fast access, like a (very high-level) cache. Need to maintain the view as the underlying tables change. Ideally, we want incremental view maintenance algorithms.
Database Management Systems, 2 nd^ Edition. R. Ramakrishnan and J. Gehrke 6
Database Management Systems, 2 nd^ Edition. R. Ramakrishnan and J. Gehrke 10
Only materialized view available: Add p5 if it isn’t there. Parts table is available: If there isn’t already a parts tuple p5 with cost >1000, add p5 to view.
expensive_parts(pno) :- parts(pno, cost), cost > 1000
Database Management Systems, 2 nd^ Edition. R. Ramakrishnan and J. Gehrke 11
Only materialized view available: If p1 is in view, no way to tell whether to delete it. (Why?)
expensive_parts(pno) :- parts(pno, cost), cost > 1000
Database Management Systems, 2 nd^ Edition. R. Ramakrishnan and J. Gehrke 12
Can’t tell whether to insert p5 into view if we’re only given the materialized view.
Supp_parts(pno) :- suppliers(sno, pno), parts(pno, cost)
Database Management Systems, 2 nd^ Edition. R. Ramakrishnan and J. Gehrke 13
Incremental Maintenance Alg: One Rule, Inserts
Step 0: For each tuple in the materialized view, store a “derivation count”. Step 1: Rewrite this rule using Seminaive rewriting, set “delta_old” relations for Rel1 and Rel2 to be the inserted tuples. Step 2: Compute the “delta_new” relations for the view relation. Important: Don’t remove duplicates! For each new tuple, maintain a “derivation count”. Step 3: Refresh the stored view by doing “multiset union” of the new and old view tuples. (I.e., update the derivation counts of existing tuples, and add the new tuples that weren’t in the view earlier.)
View(X,Y) :- Rel1(X,Z), Rel2(Z,Y)
Database Management Systems, 2 nd^ Edition. R. Ramakrishnan and J. Gehrke 14
Incremental Maintenance Alg: One Rule, Deletes
To update the derivation counts of existing tuples, we must now subtract the derivation counts of the new tuples from the counts of existing tuples.
View(X,Y) :- Rel1(X,Z), Rel2(Z,Y)
Database Management Systems, 2 nd^ Edition. R. Ramakrishnan and J. Gehrke 15
Incremental Maintenance Alg: General
Try and do this! The extension is straightforward.