NestedRelations

Nested Relations
• Flat schemas often have replicated data values in
their relations.
• Nested schemas allow us to collapse some of these
replicated data values.
NrBeds
2
2
2
1
1
RoomNr
1
2
3
4
5
(NrBeds
2
1
( RoomNr )* )*
1
2
3
4
5
NestedRelations: 1
Redundancy in Nested Schemes
• The redundancy definition is the same as for flat relations.
• If a hidden value can be uniquely determined or if a value change
causes a constraint violation, the value is redundant.
NrBeds
(NrBeds (RoomNr
2
1
2
3
RoomNr
(View)* )* )*
Sea
Forest
City
View
(View
Sea
NrBeds)* )*
2
2
Forest
1
2
2
2
City
1
3
2
2
Sea
Forest
City
(RoomNr
1
2
NestedRelations: 2
NNF: Redundancy Free Nested Schemas
Input: a canonical, acyclic, binary hypergraph H.
Output: a set of nested schemas with no potential redundancy.
Repeat
Mark an unmarked node in H as the first attribute in a new nested schema.
While an unmarked edge is incident on a marked node A:
Mark the edge.
If A  B: Add B with A; Mark B.
If A  B: Add B with A; Mark B if all B’s incident edges are marked.
If A  B: Nest B under A; Mark B.
Else (A — B): Nest B under A; Mark B if all B’s incident edges are marked.
Until all nodes have been marked
NestedRelations: 3
Nested Schema Generation Example
RoomName
Cost
NrBeds
RoomNr
View
GuestNr
GuestName
1. (NrBeds, (RoomNr, RoomName, Cost, (View)*, (GuestNr, GuestName)* )* )*
2. (RoomNr, RoomName, Cost, NrBeds, (View)*, (GuestNr, GuestName)* )*
3. (GuestNr, GuestName, RoomNr)*
(RoomNr, RoomName, Cost, NrBeds (View)* )*
NestedRelations: 4
Redundancy Prevention
x
a
1
y
b
2
z
(A
a
(B
x
y
b
y
z
This replication ...
C )* )*
1
1
2
1
2
2
… causes this
redundancy.
NestedRelations: 5
Generalization
for N-ary Relationship Sets
B
D
A
C
• “Composite nodes” can be treated as a single node.
– (B C (A)* (D)* )*
– (D (B C)* )*; (A B C)*
• Or, n-ary edges (n3) can be converted to an object set and n
binary relationship sets.
• NNF, basically:
– Schemes should be constructed along hypergraph paths.
– Schemes should not violate the natural 1-many hierarchical structure.
NestedRelations: 6