Databases Reference
In-Depth Information
SP WRAP ( { PNO , QTY } AS PQ )
yields this relation:
┌─────┬───────────────┐
│ SNO │ PQ │
├═════┼═══════════════┤
│ │ ┌─────┬─────┐ │
│ S1 │ │ PNO │ QTY │ │
│ │ ├─────┼─────┤ │
│ │ │ P1 │ 300 │ │
│ │ └─────┴─────┘ │
│ │ ┌─────┬─────┐ │
│ S1 │ │ PNO │ QTY │ │
│ │ ├─────┼─────┤ │
│ │ │ P2 │ 200 │ │
│ │ └─────┴─────┘ │
│ │ ┌─────┬─────┐ │
│ S2 │ │ PNO │ QTY │ │
│ │ ├─────┼─────┤ │
│ │ │ P1 │ 300 │ │
│ │ └─────┴─────┘ │
└─────┴───────────────┘
Note that the PQ values in this relation are tuples, not relations—PQ here is a tuple valued
attribute, not a relation valued attribute. Note also that (a) attribute PQ is double underlined (if
this relation is understood as the current value of some relvar, then the sole key for that relvar is
the entire heading); (b) attribute PNO in the three PQ values is not double underlined, because
(to say it again) those PQ values are tuples, not relations, and keys apply to relations, not tuples.
As for UNWRAP, let's call the result of the foregoing WRAP operation spw . Then the
expression
spw UNWRAP ( PQ )
returns the shipments relation we started with (the one with three tuples shown on the left of Fig.
12.1).
Here now are definitions of GROUP and UNGROUP. Note: I give these definitions here
mainly for purposes of reference. Like many formal definitions, they might be a little difficult to
understand, at least on a first reading. So I think it's important to say up front that it's not crucial
to understand them 100 percent at this stage.
Definition: Let the heading of relation r be partitioned into subsets X = { X1 , X2 ,..., Xm } and
Y = { Y1 , Y2 ..., Yn }; also, let YR be an attribute name not appearing in X . Then the
expression r GROUP ({ Y1 , Y2 , ... , Yn } AS YR ) returns a relation s . The heading of s is
{ X1 , X2 ,..., Xm , YR }, where YR is of type RELATION { Y1 , Y2 , ... , Yn }. The body of s is
defined as follows. Let z be the result of r WRAP ({ Y1 , Y2 , ... , Yn } AS YT ). For each
distinct X value x in z , let yr be the relation whose tuples are all and only those YT values
 
Search WWH ::




Custom Search