



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!




Universal Relations
The idea keeps getting reinvented ab out 3 times a year somewhere in the world.
F So let's see it once and for all, and then if you ever need it you can just implement it rather than reinventing it.
Example of Problem that the UR Solves
Supp ose we have relations E D , E O , E P , and D M , connecting employees to departments, phones, and oces, resp ectively, and departments to managers. To simplify SQL queries, we might de ne a view
create view EDOPM as select ED.E, ED.D, EO.O, EP.P, DM.M from ED, EO, EP, DM where ED.E = EO.E and EO.E = EP.E and DM.D = ED.D
Database Schema as a Hyp ergraph
O E
P
D
M
Consider a query \ nd the oces of employees managed by Sally." Without the view: select EO.O from EO, ED, DM where EO.E = EM.E and DM.D = ED.D and M = 'sally'
Using the view:
select O from EDOPM where M = 'sally'
These two are not the same!
F If, e.g., some employee rep orts to Sally but has no listed phone, then the query using the view fails to give that employee's oce.
Simple UR Mo del
The problem ab ove can b e xed if we take advantage of the fact that the various relation schemas use the same name for the same concept (and only for the same concept).
We can thus imagine a universal relation whose attributes are all the attributes app earing in any schema.
F The relation instance for this (imaginary) UR can b e thought of as the natural join of all the relations, padded with nulls if necessary.
F Sort of a multiway outerjoin.
F But in queries, we never want to see the nulls.
More precisely, to answer a query, we want to join only those relations that somehow connect the attributes of the query.
F Thus, a dangling tuple in an irrelevant relation will not a ect the answer.
Example
Query connecting O and M only go es through E O , E D , and D M , not E P.
O E
P
D
M
A UR Query-Answering Strategy
relation maps the set X of attributes mentioned by the query to a relation [X ] over which the query is answered.
Example
The \simple" UR describ ed ab ove computes [X ] by:
The Weak-Instance Window Function
A more conservative approach to establishing links is to assume that nothing is related unless it follows from a functional, multivalued, or other given dep endency.
Build a weak instance (of the universal relation) by taking the instances of the real relations and padding them with unique-value nulls.
F We use ?i for a null, where i is an integer chosen di erent from that of any other null.
Then \chase" the weak instance by applying FD's to equate symb ols (favor a real symb ol over a null) and MVD's to generate new tuples.
Finally, compute the total projection [X ] by pro jecting onto X only those tuples in the resulting weak instance that have no nulls in the columns for X.
Example
Assume relations E D and D M (employees- departments-managers) with functional dep endencies E! D and D! M. Supp ose also that the current instances are: E D = f(e 1 ; d 1 ); (e 2 ; d 1 ); (e 3 ; d 2 )g and D M = f(d 1 ; m 1 ); (d 3 ; m 2 )g.
Let the query b e \ nd all the employee- manager pairs," i.e., X = fE ; M g.
Then the weak instance starts out as
E D M e 1 d 1? 1 e 2 d 1? 2 e 3 d 2? 3 ? 4 d 1 m 1 ? 5 d 3 m 2
The only equalities one can deduce are using D! M , from which we can infer? 1 =? 2 = m 1.
The weak instance b ecomes: E D M e 1 d 1 m 1 e 2 d 1 m 1 e 3 d 2? 3 ? 4 d 1 m 1 ? 5 d 3 m 2
The total pro jection onto E M is thus f(e 1 ; m 1 ); (e 2 ; m 1 )g.