Relation Algebra
Table of Contents
1. Relation Algebra
1.1. U Union
must have the same schema
1.2. π Projection
symbolic manipulation to yield a result, which does not change the data set directly
Examples
πname (Parts) =
{(Bolt),
(Elec Wiring), (Insulation),
(Solar Shield)}
πname (Projects) =
{ (Appollo 8), (B, Apollo 10),
(Appollo 11), (Solar Shield)}
we can have multiple projections
πpart, proj (commitment) =
{(1, A) (2, B), (2, C) (3, A)
(3, B), (3, C)}
/we exclude duplicate values
πproj (commitment) = {(A), (B), (C)}
we can combine relations
πname(Parts) U piname(Projects) = …
1.3. σ Selection
we manipulate to yield elements of a set that satisify a condition
σQtyOnHand <= 100 (Parts) =
{(3, insulation, 100, sq.m), …}
σprojid = A || ProjId = D (Projects) =
{(A, Apollo 8), (D, Solar Shield)}
σqty > 500 (Commitment) = 0
σqty > 0 (Commitment) = Commitment
1.4. X Cartesian Product
Parts x Projects =
{((1, Bolt, 1000, null), (A, Apollo, 8)),
((1, Bolt, 1000, null), (B, Apollo, 10))
((1, Bolt, 1000, null), …)
((1, Bolt, 1000, null), …)
…}
by our definition tuples have to be flattened and not have nested tuples so the correct format is
Parts x Projects =
{(1, Bolt, 1000, null, A, Apollo 8),
(1, Bolt, 1000, null, B, Apollo 10)
(1, Bolt, 1000, null, …)
(1, Bolt, 1000, null, …)
…}
Schema? (PartNo, Name, QtyHand, Unit, ProjID, Name)
notice how we have two attributes with the same name
this is no good, we fix this with a simple fix
(PartNo, Parts.Name, QtyHand, Unit, ProjID, Projects.Name)