Test Notes

Intro

ER Diagrams

Attributes:

Relationships:

Weak entities:

EER:

Relational Data Model

Domain constraint: value must be in their domain.

Key constraint:

Referential integrity constraint: foreign key matches existing primary key of relation, or is null.

Semantic integrity constraint: domain-specific constraints.

EER To Relation

  1. Simple entity: new relation, pick any key as PK
  2. Weak entity: new relation, PK is owner PK + partial key
  3. 1:N relationship: FK on N side
  4. 1:1 relationship: FK on side with total participation
  5. M:N relationship: new relation with both FKs as PK
  6. Multivalued attributes: new relation, PK is owner PK + attribute value
  7. N-ary relationships: new relation with FKs as PKs
  8. Specialization/generalization
    • Any specialization: superclass has its own relation; subclasses have their own relation with their attributes; PK is FK for the superclass
    • Total specialization: subclasses have their own relation, duplicating superclass attributes
    • Disjoint specialization: single relation with properties from every subclass, plus type attribute
    • Overlapping specialization: single relation with properties from every subclass, plus Boolean for each subclass indicating if the entity is a member of the subclass
  9. Category: PK is artificial, auto-generated ID. All superclasses of the category have this as a FK

Normalization

Guidelines:

Functional Dependencies

Armstrong’s Inference Rules

  1. Reflexivity: YX    XYY \subset X \implies X \rightarrow Y
  2. Augmentation: XY    XZYZX \rightarrow Y \implies XZ \rightarrow YZ
  3. Transitivity: XYYZ    XZX \rightarrow Y \land Y \rightarrow Z \implies X \rightarrow Z

From these, the following can be generated:

  1. Decomposition: XYZ    XYXZX \rightarrow YZ \implies X \rightarrow Y \land X \rightarrow Z
  2. Union: XYXZ    XYZX \rightarrow Y \land X \rightarrow Z \implies X \rightarrow YZ
  3. Pseudo-transitivity: XYWYZ    WXZX \rightarrow Y \land WY \rightarrow Z \implies WX \rightarrow Z

Equivalence of Sets

FF covers GG if G+F+G^+ \subseteq F^+. Equivalent if FF covers GG and GG covers FF.

To test if FF covers GG, for each FD XYX \rightarrow Y in GG, check if Y{X}F+Y \subseteq \{X\}_F^+.

Minimal Sets

Minimal if RHS of all FDs is a single element and:

leads to a set that is not equivalent.

Normal Forms

If elements can be removed from the RHS, then it is a partial FD. Otherwise, it is called a full FD.

If XYX \rightarrow Y and YZY \rightarrow Z, XZX \rightarrow Z is a transitive functional dependency.

Minimal Cover Algorithm

G = {}
for fd in F:
  for el in fd.lhs
    G.append(FD(el, fd.rhs)) # Decomposition

for i in range(len(G)):
  fd = G[i]
  for el in fd.lhs:
    J = G.copy()
    J.replace(fd, FD(fd.lhs - el, fd.rhs))
    # For each FD, see if any element can be removed from the LHS
    if cover(fd.lhs - el, G) == cover(fd.lhs - el, J):
        # Covers equal, so element can be removed
        G = J

for fd in G:
  if cover(fd.lhs, G - fd) == cover(fd.lhs, G):
    G.remove(fd)

Physical Layer

Hashing

RAID 0: striping data; 1: mirroring.

Indexing

B-Trees

Structure with pointer to subtrees and (key value + pointer) pairs that divide the subtree (all left subtree values less than key value etc.): kk child nodes, k1k-1 key-pointer pairs. Nodes must be at least half full.

B+ tree: internal nodes store only key values. Leaf nodes have key value + pointer pairs, plus pointer to next leaf node in the tree.

Transactions

ACID:

Misc.

Materialized evaluation: result of temporary relation stored (e.g. comparing value to max value from nested operation). c.f. pipelined evaluation.