Databases Reference
In-Depth Information
from tuples in z in which the X value is x ; let t be a tuple of type TUPLE { X , YR } with X
value x and YR value yr ; then, and only then, t is a tuple of s .
Definition: Let relation s have an attribute YR of type RELATION { Y1 , Y2 ,..., Yn }, and let
X = { X1 , X2 ,..., Xm } be all of the attributes of s other than YR ; also, let no Xi have the same
name as any Yj (0 ≤ i m , 0 ≤ j n ). Then the expression s UNGROUP ( YR ) returns a
relation r . The heading of r is { X1 , X2 ,..., Xm , Y1 , Y2 ,..., Yn }. The body of r is defined as
follows. Let z be a relation with heading { X1 , X2 ,..., Xm , YT }, where YT is of type TUPLE
{ Y1 , Y2 ,..., Yn }, and body defined thus: For each tuple of s , z contains a set of tuples of type
{ X , YT }, one ( t , say) for each tuple in the YR value in that s tuple; each such tuple t contains
an X value equal to the X value from the s tuple in question and a YT value equal to some
tuple from the YR value in the s tuple in question. Let z contain no other tuples. Then r is
the result of z UNWRAP ( YT ).
Note: Given a relation r and some grouping of r, there's always an inverse ungrouping that
yields r again; however, the converse isn't necessarily so. The following example illustrates this
point. Consider the relation—call it spq —shown on the left in Fig. 12.2; note in particular that
the PQ value for supplier S2 in spq is an empty relation. The expression spq UNGROUP (PQ)
yields the relation—call it sp —shown in the middle of the figure. And the expression sp
GROUP ({PNO,QTY} AS PQ) then yields the relation shown on the right, which is obviously
not equal to the original relation spq . 4
┌─────┬───────────────┐ ┌─────┬─────┬─────┐ ┌─────┬───────────────┐
│ SNO │ PQ │ │ SNO │ PNO │ QTY │ │ SNO │ PQ │
├═════┼───────────────┤ ├═════┼═════┼─────┤ ├═════┼───────────────┤
│ │ ┌─────┬─────┐ │ │ S1 │ P1 │ 300 │ │ │ ┌─────┬─────┐ │
│ S1 │ │ PNO │ QTY │ │ │ S1 │ P2 │ 200 │ │ S1 │ │ PNO │ QTY │ │
│ │ ├═════┼─────┤ │ └─────┴─────┴─────┘ │ │ ├═════┼─────┤ │
│ │ │ P1 │ 300 │ │ │ │ │ P1 │ 300 │ │
│ │ │ P2 │ 200 │ │ │ │ │ P2 │ 200 │ │
│ │ └─────┴─────┘ │ │ │ └─────┴─────┘ │
│ │ ┌─────┬─────┐ │ └─────┴───────────────┘
│ S2 │ │ PNO │ QTY │ │
│ │ ├═════┼─────┤ │
│ │ └─────┴─────┘ │
└─────┴───────────────┘
Fig. 12.2: UNGROUP and GROUP aren't necessarily inverses
4 But do you think those two relations are information equivalent? (You might want to revisit this question after reading Chapter
14.)
Search WWH ::




Custom Search