Relational Model


Notes on relational model

Tuples

A tuple is an unordered set of triplets (also called components) consisting of attribute names, types, and values {(α1,T1,v1),(α2,T2,v2),...,(αi,Ti,vi)}\{ (\alpha_1, T_1, v_1), (\alpha_2, T_2, v_2), ..., (\alpha_i, T_i, v_i) \}. It loosely corresponds to the concept of a “row” in SQL. A tuple is also a functional mapping from attributes to their respective values.

Given a tuple SS:

A pair (α,T)(\alpha, T) is an attribute of a tuple SS if the tuple has a matching triplet: v(α,T,v)S\exists v \bullet (\alpha, T, v) \in S. The set of all attributes of a tuple SS is the heading of SS.

The type of a tuple of determined by its heading. Two tuples S1S_1 and S2S_2 are of the same type iff heading(S1)=heading(S2)heading(S_1) = heading(S_2).

Every subset of a tuple is also a valid tuple, including the empty set (the zero-tuple).

Degree (or Arity)

The arity or degree of a tuple SS is its set cardinality, which corresponds to the number of triplets it contains.

Notice that the degree of a tuple SS is also equal to the set cardinality of its heading: degree(S)=|heading(S)|degree(S) = \vert heading(S) \vert.

Equality

Two tuples S1S_1 and S2S_2 are considered equal if they share the same heading and attribute values:

S1=S2heading(S1)=heading(S2)(α,T)heading(S1)vT(α,T,v)S1(α,T,v)S2\begin{align} S_1 = S_2 \iff &heading(S_1) = heading(S_2) \land \\ &\forall (\alpha, T) \in heading(S_1) \exists v \in T \bullet (\alpha, T, v) \in S_1 \land (\alpha, T, v) \in S_2 \end{align}

Zero Tuple

The unique tuple with arity zero is called the nullary or zero tuple. Its heading is the empty set: heading()=heading(\emptyset) = \emptyset.

Attributes

An attribute is a pair (α,T)(\alpha, T) where α\alpha is the attribute name and TT corresponds to its type.

Closure

Given a relation RR and a set of attributes Mheading(R)M \subseteq heading(R), the closure M+M^{+} of MM under a set of functional dependencies SS is the family union of all the attributes that are dependent of MM in S+S^{+}: M+={α(Mα)S+}M^{+} = \bigcup \{ \alpha \mid (M \rightarrow \alpha) \in S^{+} \}.

If M+=heading(R)M^{+} = heading(R) then MM is a super key for RR.

Headings

A heading is a set of attributes {(α1,T1),(α2,T2),...,(αi,Ti)}\{ (\alpha_1, T_1), (\alpha_2, T_2), ..., (\alpha_i, T_i) \}. The heading of a tuple SS determines the type of the tuple and its equal to its set of attributes: heading(S)={(α,T)(α,T,v)S}heading(S) = \{ (\alpha, T) \mid (\alpha, T, v) \in S \}.

Given a heading HH:

Relations

A relation is an object (H,B)(H, B) containing a heading and a body where the body is an unordered set of tuples (which means no duplicates), and where heading(H,B)=Hheading(H, B) = H and body(H,B)=Bbody(H, B) = B. The type of a relation is determined by the type of its heading.

Given a relation RR:

Keys

Super Keys

Given a relation RR, a set of attributes Mheading(R)M \subseteq heading(R) is a super key for RR if all the attributes of RR are funtionally dependent on MM. More formally: Mheading(R)M \rightarrow heading(R).

In terms of candidate keys, super keys are sets of attributes that contain some candidate key as a subset.

Candidate Keys

A candidate key is an irreducible super key. Given a relation RR, a set of attributes Mheading(R)M \subseteq heading(R) is a candidate key for RR it is the minimal Mheading(R)M \subseteq heading(R) such that Mheading(R)M \rightarrow heading(R).

Operations

Cardinality

The cardinality of a relation RR is equal to the cardinality of its body: |R|=|body(R)|\vert R \vert = \vert body(R) \vert.

Degree (or Arity)

The arity or degree of a relation RR is equal to the arity of its heading: degree(R)=degree(heading(R))degree(R) = degree(heading(R)).

Membership

Given relation RR and tuple SS, we may use the set membership operator to express that a relation contains a tuple in its body: SRSbody(R)S \in R \iff S \in body(R).

Equality

Two relations R1R_1 and R2R_2 are considered equal if they have the same heading (i.e. they are of the same type) and the same body: R1=R2heading(R1)=heading(R2)body(R1)=body(R2)R_1 = R_2 \iff heading(R_1) = heading(R_2) \land body(R_1) = body(R_2).

Subset

A relation R1R_1 is a subset of another relation R2R_2 if they have the same type (i.e. they share the same heading) and the body of R1R_1 is a subset of the body of R2R_2: R1R2heading(R1)=heading(R2)body(R1)body(R2)R_1 \subseteq R_2 \iff heading(R_1) = heading(R_2) \land body(R_1) \subseteq body(R_2).

Special Relations

Dum

The special relation DumDum contains an empty heading and an empty body:

Dee

The special relation DeeDee contains an empty heading and a body containing the empty tuple, which matches the type of the empty heading:

The relation DeeDee can only have at most the empty tuple as an element.

Functional Dependency

Given a relation RR and two sets of attributes Xheading(R)X \subseteq heading(R) and Yheading(R)Y \subseteq heading(R), the functional dependency XYX \rightarrow Y means that in RR the values of YY are determined by the values of XX. The set of attributes at the left hand side of the arrow (XX) is called the determinant, and the other set of attributes (YY) is called the dependent.

Trivial Dependencies

A functional dependency XYX \rightarrow Y is trivial if its dependent is a subset of its determinant: YXY \subseteq X. For example: {P,Q}{P}\{ P, Q \} \rightarrow \{ P \}.

Armstrong’s Axioms (Inference Rules)

Also called inference rules, are a set of primary rules to infer new functional dependencies from an existing set of functional dependencies. Given relation RR and A,B,Cheading(R)A, B, C \subseteq heading(R):

The following additional inference rules are derived from the primary rules:

General Unification Theorem

The theorem states that if ABA \rightarrow B and CDC \rightarrow D, then (A(C\B))(BD)(A \cup (C \setminus B)) \rightarrow (B \cup D).

Closure

The closure of functional dependency of a set of functional dependencies SS is denoted S+S^{+}, and it corresponds to the union of SS and the functional dependencies that are derived from SS.

Cover

Given two sets of functional dependencies PP and QQ for a given relation, QQ is a cover for PP if P+Q+P^{+} \subseteq Q^{+}.

Equivalence

Given two sets of functional dependencies PP and QQ for a given relation, PP is equivalent to QQ if P+=Q+P^{+} = Q^{+}, which means that PP is a cover for QQ and QQ is a cover for PP.

Irreducibility

A set of functional dependencies SS is irreducible (also called minimal) if and only if:

Every set of functional dependencies has at least one equivalent set that is irreducible. These sets are called irreducible equivalents.