Lecture 5
Lecture 5
◼ Involves:
❑ View management
❑ Security control
❑ Integrity control
◼ Objective :
❑ Ensure that authorized users perform correct operations on the
database, contributing to the maintenance of the database
integrity.
3
View Management
Example :
4
Query Modification
SELECT ENAME,PNO,RESP
FROM EMP, ASG
WHERE EMP.ENO = ASG.ENO
AND TITLE = "Syst. Anal."
5
View Management
◼ To restrict access
CREATE VIEW ESAME
AS SELECT *
FROM EMP E1, EMP E2
WHERE E1.TITLE = E2.TITLE
AND E1.ENO = USER
◼ Query
SELECT *
FROM ESAME
6
View Updates
◼ Updatable
CREATE VIEW SYSAN(ENO,ENAME)
AS SELECT ENO,ENAME
FROM EMP
WHERE TITLE="Syst. Anal."
◼ Non-updatable
CREATE VIEW EG(ENAME,RESP)
AS SELECT ENAME,RESP
FROM EMP, ASG
WHERE EMP.ENO=ASG.ENO
7
View Management in Distributed DBMS
8
Materialized View
9
Materialized View Maintenance
10
When to Refresh a View
◼ Immediate mode
❑ As part of the updating transaction, e.g. through 2PC
❑ View always consistent with base data and fast queries
❑ But increased transaction time to update base data
◼ Deferred mode (preferred in practice)
❑ Through separate refresh transactions
◼ No penalty on the updating transactions
❑ Triggered at different times with different trade-offs
◼ Lazily: just before evaluating a query on the view
◼ Periodically: every hour, every day, etc.
◼ Forcedly: after a number of predefined updates
11
How to Refresh a View
12
Differential Relations
13
Example
14
15
16
17
18
19
Counting Algorithm
◼ Basic idea
❑ Maintain a count of the number of derivations for each tuple in
the view
❑ Increment (resp. decrement) tuple counts based on insertions
(resp. deletions)
❑ A tuple in the view whose count is zero can be deleted
◼ Algorithm
1. Compute V+ and V- using V, base relations and diff. relations
2. Compute positive in V+ and negative counts in V-
3. Compute V+ (V – V- ), deleting each tuple in V with count=0
◼ Optimal: computes exactly the view tuples that are
inserted or deleted
© 2020, M.T. Özsu & P. Valduriez 20