%% LyX 1.3 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english,beamerthemelined]{beamer}
\usepackage{ae}
\usepackage{aecompl}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{graphicx}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Bold symbol macro for standard LaTeX users
\providecommand{\boldsymbol}[1]{\mbox{\boldmath $#1$}}

%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
 \AtBeginDocument{
   \let\origtableofcontents=\tableofcontents
   \def\tableofcontents{\@ifnextchar[{\origtableofcontents}{\gobbletableofcontents}}
   \def\gobbletableofcontents#1{\origtableofcontents}
 }
 \makeatletter
 \long\def\lyxframe#1{\@lyxframe#1\@lyxframestop}%
 \def\@lyxframe{\@ifnextchar<{\@@lyxframe}{\@@lyxframe<*>}}%
 \def\@@lyxframe<#1>{\@ifnextchar[{\@@@lyxframe<#1>}{\@@@lyxframe<#1>[]}}
 \def\@@@lyxframe<#1>[{\@ifnextchar<{\@@@@@lyxframe<#1>[}{\@@@@lyxframe<#1>[<*>][}}
 \def\@@@@@lyxframe<#1>[#2]{\@ifnextchar[{\@@@@lyxframe<#1>[#2]}{\@@@@lyxframe<#1>[#2][]}}
 \long\def\@@@@lyxframe<#1>[#2][#3]#4\@lyxframestop#5\lyxframeend{%
   \frame<#1>[#2][#3]{\frametitle{#4}#5}}
 \makeatother
 \def\lyxframeend{} % In case there is a superfluous frame end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{lecture,cs4604}


% make \underline overlay-specification aware.
% \renewcommand<>{\underline}[1]{\uncover#2{\beameroriginal{\underline}{#1}}}
% \newcommand<>{\bunderline}[1]{\uncover#2{\underline}{#1}}

% macro for a set. extra pair of braces inside \ensuremath to ensure
% the set is typseset in one line.
\newcommand{\set}[1]{\ensuremath{{\{#1\}}}}

\makeatother
\begin{document}

\title[CS 4604: Functional Dependencies]{Functional Dependencies}


\author[T. M. Murali]{T. M. Murali }


\date{October 18, 25, 2010}

\frame{\maketitle}

\lyxframe{Midterm Review}
\begin{itemize}

\pause
\item The database server set up is driving me NUTS!\pause

% \item Have shorter homeworks \pause but more frequent ones.
% \pause

\item The class is slow (no 3NF yet). Why are we doing design before learning
  normalisation? It seems odd to teach relational models
  after SQL. \pause

% \item Homeworks/exams are very challenging.\pause

\item Homework grading is strict/uneven. \pause

\item Increase amount of examples/hands-on work.\pause

% \item Some questions on the midterm examination were ambiguous.\pause


\item Make the lectures more interactive. \pause

\item Office hours change a lot.\pause


\item Wish the project was free form.\pause

\item It would be nice to have a table of RA symbols and E/R diagram
  shapes. % \pause

% \item Provide more help with PostgreSQL.
\end{itemize}
\lyxframeend{}


\section{Basics of FDs}


\lyxframe{Example}

\centerline{\includegraphics[height=0.3\textheight]{figs/er-students-advisors}}
\begin{itemize}
\item Convert to relations:\pause
\item[] \texttt{Students(Id, Name)}
\item[] \texttt{Advisors(Id, Name)}
\item[] \texttt{Advises(StudentId, AdvisorId)}
\item[] \texttt{Favourite(StudentId, AdvisorId)}

\pause
\item Suppose we perversely decide to convert \texttt{Students},
  \texttt{Advises}, and \texttt{Favourite} into one relation.
\item[] \texttt{Students(Id, Name, AdvisorId, AdvisorName, FavouriteAdvisorId)}
\end{itemize}
\lyxframeend{}


\lyxframe{Example of a Bad Relation}
\begin{itemize}
\item[] \texttt{Students(Id, Name, AdvisorId, AdvisorName, FavouriteAdvisorId)}
\item If you know a student's \texttt{Id}, can you determine the values of any
  other attributes? \pause \texttt{Name} and \texttt{FavouriteAdvisorId}.
\pause
\item[] \ttfd{Id}{Name}
\item[] \ttfd{Id}{FavouriteAdvisorId}\pause
\item[] \ttfd{AdvisorId}{\pause AdvisorName} \pause
\item Can we say \ttfd{Id}{AdvisorId}? \pause NO! \texttt{Id} is not a key for the \texttt{Students} relation.\pause

\item What is the key for the \texttt{Students}? \pause \set{\texttt{Id,
      AdvisorId}}. \pause
\item Why is this relation ``bad?'' \pause Parts of the key determine
  other attributes.
%  because the key does not determine the other attributes.
% \item Decomposing relation into three relations \texttt{Students},
%   \texttt{Advisors} and \texttt{Advises} fixes the problem.
\end{itemize}
\lyxframeend{}


\lyxframe{Motivation for Functional Dependencies}
\begin{itemize}
\item Reason about constraints on attributes in a relation.
\item Procedurally determine the keys of a relation.
\item Detect when a relation has redundant information.
\item Improve database designs systematically using normalisation.
\end{itemize}

\lyxframeend{}


\lyxframe{Definition of Functional Dependency}
\begin{itemize}
\item If $t$ is a tuple in a relation $R$ and $A$ is an attribute of
  $R$, then $t_A$ is the value of attribute $A$ in tuple $t$.
\item<2-> The FD \ttfd{AdvisorId}{AdvisorName} holds in $R$ if in every instance of $R$, for
  every pair of tuples $t$ and $u$
\item[]<3-> if $t_{\mathtt{AdvisorId}} = u_{\mathtt{AdvisorId}}$, then
  $t_{\mathtt{AdvisorName}} = u_{\mathtt{AdvisorName}}$. 
% \item<4-> The FD \ttfd{AdvisorId}{AdvisorName} holds in $R$ if in every instance of $R$, for
%   every pair of tuples $t$ and $u$
% \item[]<5-> if $t_{\mathtt{AdvisorId}} = u_{\mathtt{AdvisorId}}$, then
%   $t_{\mathtt{AdvisorName}} = u_{\mathtt{AdvisorName}}$. 


\end{itemize}

% \centerline{\small\fbox{\texttt{Students(Id, Name, AdvisorId, AdvisorName, FavId)}}}
% \begin{center}
%   \small
%   % \texttt{CoursesTaken}\\
%   \begin{tabular}{|c|c|c|c|c|}
%     \hline 
%     \texttt{Id}&
%     \texttt{Name}&
%     \texttt{AdvisorId} &
%     \texttt{AdvisorName} &
%     \texttt{FavId} 
%     \tabularnewline
%     \hline
%     \hline 
%     HG&
%     Hermione Grainger&
%     AD&
%     Albus Dumbledore&
%     HD
%     \tabularnewline
%     \hline 
%     HG&
%     Hermione Grainger&
%     HD &
%     Hagrid&
%     HD
%     \tabularnewline
%     \hline 
%     DM&
%     Draco Malfoy&
%     SS&
%     Severus Snape&
%     SS
%     \tabularnewline
%     \hline 
%     DM&
%     Draco Malfoy&
%     MM&
%     Minerva McGonagall &
%     SS
%     \tabularnewline
%     \hline 
%     HP&
%     Harry Potter&
%     AD&
%     Albus Dumbledore&
%     AD
%     \tabularnewline
%     \hline 
%   \end{tabular}
% \end{center}
\lyxframeend{}

\lyxframe{Definition of Functional Dependencies}
A \emph{functional dependency} (FD) on a relation $R$ is a statement

\begin{itemize}
\item If two tuples in $R$ agree on attributes $A_1,
  A_2, \ldots A_n$ then they agree on attribute $B$.
\item Notation: \fd{A_1 A_2 \ldots A_n}{B} \pause
\item FD says that for every pair of tuples $t$ and $u$ in any instance
  of $R$, \pause if $t_{A_1} = u_{A_1}$ and $t_{A_2} = u_{A_2}$ and
  $\ldots t_{A_n} = u_{A_n}$, then $t_{B} = u_{B}$.
\item \emph{The set of attributes $A_1, A_2, \ldots A_n$ \mydef{functionally
    determine} $B$}.
\item An FD is a constraint on a single relation schema. It must hold on
  every instance of the relation.
\item \alert{You cannot deduce an FD  from a relation instance.}
\end{itemize}

% \begin{center}
% \small  \begin{tabular}[c]{|c|c|c|c|}
%     \hline
%     $A$ & $B$ & $C$ & $D$
%     \\  \hline
%     \hline
%     a1 & b1 & c1 &d1 \\\hline
%     a1 & b1 & c1 &d2 \\\hline
%     a1 & b2 & c2 &d1 \\\hline
%     a1 & b2 & c2 &d1 \\\hline
%   \end{tabular}
% \end{center}

% Does this relation instance satisfy the FD 
% %\begin{itemize}
% %\item 
% \fd{AB}{C}? \pause \fd{AC}{D}? \pause \fd{CD}{A}?
% %\end{itemize}

% \begin{itemize}
% \item If $A_1, A_2, \ldots A_n$ functionally determine more
%   than one attribute, i.e.,
% \item[] \fd{A_1 A_2 \ldots A_n}{B_1}
% \item[] \fd{A_1 A_2 \ldots A_n}{B_2}
% \item[] $\ldots$
% \item[] \fd{A_1 A_2 \ldots A_n}{B_m}
% \item then we can combine these FDs into a single FD
% \item[] \fd{A_1 A_2 \ldots A_n}{B_1 B_2 \ldots B_m}
% \end{itemize}

\lyxframeend{}

\lyxframe{Examples of FDs}

\begin{itemize}
\item What FDs can we assert for the relation
\end{itemize}

\centerline{\small\fbox{\texttt{Courses(Number, DeptName, CourseName,
      Classroom, Enrollment)}}}
\begin{center}
\small
%  \texttt{CoursesTaken}\\
  \begin{tabular}{|c|c|c|c|c|}
    \hline 
    \texttt{Number}&
    \texttt{DeptName}&
    \texttt{CourseName} &
    \texttt{Classroom} &
    \texttt{Enrollment} 
    \tabularnewline
    \hline
    \hline 
    4604&
    CS&
    Databases&
    TORG 1020&
    45
    \tabularnewline
    \hline 
    4604&
    Dance&
    Tree Dancing &
    Drillfield&
    45
    \tabularnewline
    \hline 
    4604&
    English&
    The Basis of Data&
    Williams 44&
    45
    \tabularnewline
    \hline 
    2604&
    CS&
    Data Structures&
    MCB 114&
    100
    \tabularnewline
    \hline 
    2604&
    Physics&
    Dark Matter&
    Williams 44&
    100
    \tabularnewline
    \hline 
  \end{tabular}
\end{center}

\pause
\begin{itemize}
\item[] \fd{\texttt{Number DeptName}}{\texttt{CourseName}}
\item[] \fd{\texttt{Number DeptName}}{\texttt{Classroom}}
\item[] \fd{\texttt{Number DeptName}}{\texttt{Enrollment}}
\pause
% \item Since all three FDs have exactly the same attributes on the left
%   hand side, we can combine them into a single FD

\item[] \fd{\texttt{Number DeptName}}{\texttt{CourseName Classroom Enrollment}}
\pause
\item Is \ttfd{Number}{Enrollment} an FD?
% \pause
% \item What about \ttfd{Classroom}{Enrollment}?
\end{itemize}

\lyxframeend{}


\lyxframe{Where do FDs come from?}
\pause
\begin{itemize}
\item ``Keyness'' of attributes.
\item Domain and application constraints.
\item Real world constraints, e.g., \ttfd{ProfessorID\ Time}{Classroom}

\end{itemize}
\lyxframeend{}


\lyxframe{Definition of Keys}
\begin{itemize}
\item FDs allow us to formally define keys.
\item A set of attributes $\{A_1, A_2, \ldots A_n\}$ is a \emph{key} for
  a relation $R$ if
  \begin{description}
  \item[\textbf{Uniqueness}] $\{A_1, A_2, \ldots A_n\}$ functionally
    determine all the other attributes of $R$ and
  \item[\textbf{Minimality}] no proper subset of $\{A_1, A_2, \ldots A_n\}$ functionally
    determines all the other attributes of $R$.
  \end{description}
\pause
\item A \emph{superkey} is a set of attributes that has the uniqueness
  property but is not necessarily minimal.
\item If a relation has multiple keys, specify one to be the
  \emph{primary key}.
\item Convention: in a relational schema, underline the attributes
  of the primary key.
\item If a key has only one attribute $A$, we say that $A$ rather than
  $\{A\}$ is a key.
\end{itemize}

\lyxframeend{}

\lyxframe{Example of Keys}
\begin{itemize}
\item What is the key for
\item[] \texttt{Courses(\only<1>{Number}\only<2->{\underline{Number}},
    \only<1>{DeptName}\only<2->{\underline{DeptName}}, CourseName, Classroom,
    Enrollment)}?
\end{itemize}
\pause
\begin{itemize}
\item The key is \texttt{\{Number, DeptName\}}.
  \begin{itemize}
  \item These attributes functionally determine every other attribute.
  \item No proper subset of \texttt{\{Number, DeptName\}} has this property.
  \end{itemize}
\pause
\item What is the key for
\item[]\texttt{Teach(\only<3>{Number}\only<4->{\underline{Number}}, \only<3>{DepartmentName}\only<4->{\underline{DepartmentName}}, ProfessorName, Classroom)}?
\pause

\item The key is \texttt{\{Number, DepartmentName\}}. Why?
\end{itemize}


\lyxframeend{}

\lyxframe{Keys in the Conversion from E/R to Relational Designs}
\begin{itemize}
\item If the relation comes from an entity set, the key attributes of
  the relation are precisely the key attributes of the entity set.
\pause
\item If the relation comes from a binary relationship $R$ between
  entity sets $E$ and $F$:\pause
  \begin{itemize}
  \item $R$ is many-many: \pause key attributes of the relation are the key
    attributes of $E$ and of $F$.\pause
  \item $R$ is many-one from $E$ to $F$: \pause key attributes of the
    relation are the key attributes of $E$.\pause
  \item $R$ is one-one: \pause key attributes of the relation are the
    key attributes of $E$ or of $F$.
  \end{itemize}
\pause
\item If the relationship $R$ is multiway\pause{}, we need to reason about
  the FDs that $R$ satisfies.
  \begin{itemize}
  \item There is no simple rule.
  \item If $R$ has an arrow towards entity set $E$, at least one key for
    the relation for $R$ excludes the key for $E$.
  \end{itemize}
\end{itemize}
\lyxframeend{}

\section{Manipulating FDs}

\lyxframe{Rules for Manipulating FDs}
\begin{itemize}
\item Learn how to reason about FDs.
\item Define rules for deriving new FDs from a given set of FDs.
\item Next class: use these rules to remove ``anomalies'' from
  relational designs.
\pause
\item Example: A relation $R$ with attributes $A$, $B$, and $C$,
  satisfies the FDs \fd{A}{B} and \fd{B}{C}. What other FDs does it
  satisfy? \pause \fd{A}{C}.
  \pause
\item What is the key for $R$? \pause $A$, because \fd{A}{B} and \fd{A}{C}.
\end{itemize}


\lyxframeend{}

\lyxframe{Equivalence of FDs}
\begin{itemize}
\item An FD $F$ \emph{follows} from a set of FDs $T$ if every relation
  instance that satisfies all the FDs in $T$ also satisfies $F$.
  \begin{itemize}
  \item $\fd{A}{C}$ follows from $T = \{\fd{A}{B}, \fd{B}{C}\}$.
  \item Does $T$ follow from $S$?
  \end{itemize}
\pause
\item Two sets of FDs $S$ and $T$ are \emph{equivalent} if each FD in
  $S$ follows from $T$ and each FD in $T$ follows from $S$.
  \begin{itemize}
  \item $S = \{\fd{A}{B}, \fd{B}{C}, \fd{A}{C}\}$ and $T = \{\fd{A}{B},
    \fd{B}{C}\}$ are equivalent.
  \end{itemize}
\pause

\item These notions are useful in deriving new FDs from a given set of FDs.
\end{itemize}

\lyxframeend{}

\lyxframe{Splitting and Combining FDs}
\begin{itemize}
\item The set of FDs
\item[] \fd{A_1 A_2 \ldots A_n}{B_1}
\item[] \fd{A_1 A_2 \ldots A_n}{B_2} 
\item[] $\vdots$
%\item[] \fd{A_1 A_2 \ldots A_n}{B_{m - 1}}
\item[] \fd{A_1 A_2 \ldots A_n}{B_m}

\item[] is equivalent to the  FD 

\item[]$\fd{A_1 A_2 \ldots A_n}{B_1 B_2 \ldots B_m}$.

\item This equivalence implies two rules.
  \begin{itemize}
  \item \emph{Splitting rule}%: we can split  an FD into the set of FDs
%in $S$. 
  \item \emph{Combining rule}%: we can combine the set of $m$ FDs in $S$
%into the single FD $T$. 
  \item These rules work because all the FDs in $S$ and $T$ have
    identical left hand sides.
  \end{itemize}
\end{itemize}

\lyxframeend{}

\lyxframe{Splitting and Combining FDs}
\begin{itemize}
\item Can we split and combine left hand sides of FDs?
\pause

\item For the relation \texttt{Courses}, is the FD
\item[] \fd{\texttt{Number
      DeptName}}{\texttt{CourseName}}
\item[] equivalent to the set of FDs 

\item[] 
\set{\ttfd{Number}{CourseName}, \ttfd{DeptName}{CourseName}}? \pause NO!
\end{itemize}
\lyxframeend{}

\lyxframe{Triviality of FDs}

An FD \fd{A_1 A_2 \ldots A_n}{B_1 B_2 \ldots B_m} is
\pause
\begin{itemize}
\item \emph{trivial} if the $B$'s are a subset of the $A$'s, \pause i.e., $\set{B_1, B_2,
    \ldots B_n} \subseteq \set{A_1, A_2, \ldots A_n}$.
\pause
\item \emph{non-trivial} if at least one $B$ is not among the A's,
  \pause i.e.,
  $\set{B_1, B_2, \ldots B_n} - \set{A_1, A_2, \ldots A_n}
  \not= \emptyset$.
\pause
\item \emph{completely non-trivial} if none of the $B$'s are among the
  $A$'s, \pause i.e., $\set{B_1, B_2, \ldots B_n} \cap \set{A_1, A_2, \ldots A_n} =
  \emptyset$.
\pause
\item What good are trivial and non-trivial dependencies?
  \begin{itemize}
  \item Trivial dependencies are always true.
  \item They help simplify reasoning about FDs.
  \end{itemize}
\pause
\item \emph{Trivial dependency rule}: The  FD \fd{A_1 A_2 \ldots
    A_n}{B_1 B_2 \ldots B_m} is equivalent to the 
   FD \fd{A_1 A_2 \ldots A_n}{C_1 C_2 \ldots C_k}, where the $C$'s are
   those $B$'s that are not $A$'s, i.e.,
   $\set{C_1, C_2, \ldots, C_k} = \set{B_1, B_2, \ldots, B_m} - \set{A_1, A_2, \ldots,
    A_n}$.
\end{itemize}
\lyxframeend{}

\section{Closures and Keys}

\lyxframe{Closures of Attributes: Example}
Suppose a relation with attributes $A, B, C, D, E,$ and $F$ satisfies the
FDs
\begin{itemize}
\item[] \fd{AB}{C} \, \fd{BC}{AD} \, \fd{D}{E}, \, \fd{CF}{B}
\end{itemize}
Given these FDs,
\begin{itemize}
\item what is the set $X$ of attributes such that
  \fd{AB}{X} is true? \pause $X = \set{A, B, C, D, E}$, i.e., \fd{AB}{ABCDE}.\pause
\item what is the set $Y$ of attributes such that
  \fd{BCF}{Y} is true? \pause $Y = \set{A, B, C, D, E, F}$, i.e., \fd{BCF}{ABCDEF}\pause
\item what is the set $Z$ of attributes such that
  \fd{AF}{Z} is true? \pause $Z = \set{A, F}$, i.e., \fd{AF}{AF}.
\pause
\item $X, Y,$ and $Z$ are the \emph{closures} of \set{A, B}, \set{B, C,
    F}, and \set{A, F}, respectively.\pause
\item \set{B, C, F} is a \pause superkey.
\end{itemize}
\lyxframeend{}

\lyxframe{Closures of Attributes: Definition}
Given 
\begin{itemize}
\item a set of attributes \set{A_1, A_2, \ldots, A_n} and
\item a set of FDs $S$, 
\end{itemize}
the \mydef{closure} of \set{A_1, A_2, \ldots, A_n} under the FDs in $S$
is
\begin{itemize}
\item the set of attributes \set{B_1, B_2, \ldots, B_m} such that for $1
  \leq i \leq m$, the FD \fd{A_1 A_2 \ldots A_n}{B_i} follows from $S$.
\item the closure is denoted by \closure{A_1, A_2, \ldots, A_n}.
\pause
\item Which attributes must \closure{A_1, A_2, \ldots, A_n} contain at a
  minimum? \pause \set{A_1, A_2, \ldots, A_n}. Why? \pause \fd{A_1 A_2 \ldots A_n}{A_i} is
  a trivial FD.
\end{itemize}

\lyxframeend{}

\lyxframe{Closures of Attributes: Algorithm}
Given 
\begin{itemize}
\item a set of attributes \set{A_1, A_2, \ldots, A_n} and
\item a set of FDs $S$,
\item compute $X = \closure{A_1, A_2, \ldots, A_n}$.
\end{itemize}
\pause
\begin{enumerate}
\item Use the splitting rule so that each FD in $S$ has one attribute on
  the right.
\item Set $X \leftarrow \set{A_1, A_2, \ldots, A_n}$.
\item Find an FD \fd{B_1 B_2\ldots B_k}{C} in $S$ such that $\set{B_1,
    B_2,\ldots B_k} \subseteq X$ but $C \not\in X$.
\item Add $C$ to $X$.
\item Repeat the last two steps until you cannot find such an attribute
  $C$.
\item The final value of $X$ is the desired closure.
\end{enumerate}
\pause
\begin{itemize}
\item Why does the algorithm compute the closure correctly? Read Chapter
  3.2.5 of the textbook.
\end{itemize}
\lyxframeend{}

\lyxframe{Why is the Concept of Closures Useful?}

\begin{enumerate}
\item Prove correctness of rules for manipulating
  FDs. \pause For example,
  \begin{itemize}
  \item \emph{Transitive rule}: if \\\fd{A_1A_2\ldots A_n}{B_1B_2\ldots
      B_m} \\and \\\fd{B_1B_2\ldots B_m}{C_1C_2\ldots C_k} \\then\\
    \fd{A_1A_2\ldots A_n}{C_1C_2\ldots C_k}.\pause
  \item To prove this rule, simply check if $\set{C_1, C_2, \ldots,
      C_k} \subseteq \closure{A_1, A_2, \ldots, A_n}$.
  \end{itemize}\pause
\item Check if a ``new'' FD \fd{A_1A_2\ldots A_n}{B} follows from a set
  of FDs $S$: simply check if $B$ is in \closure{A_1, A_2, \ldots A_n}
  under $S$.\pause
\item Procedurally define keys. \pause A set of attributes
  $X$ is a key for a relation $R$ if and only if 
  \begin{itemize}
  \item \closure{X} is the set of all attributes of $R$ and
  \item for no attribute $A \in X$ is \closure{X - \set{A}} the set of
    all attributes of $R$.
  \end{itemize}
\end{enumerate}
\lyxframeend{}


\lyxframe{Examples of Closure Computations}
\begin{itemize}
\item Consider the ``bad'' relation \texttt{Students(Id, Name, AdvisorId, AdvisorName, FavouriteAdvisorId)}.
\item What are the FDs that hold in this relation?
\item[] \ttfd{Id}{Name}
\item[] \ttfd{Id}{FavouriteAdvisorId}
\item[] \ttfd{AdvisorId}{AdvisorName} \pause

\item To compute the key for this relation,
  \begin{enumerate}
  \item Compute the closures for all sets of attributes.
  \item Find the minimal set of attributes whose closure is the set of
    all attributes.
  \end{enumerate}
\end{itemize}

\lyxframeend{}




\myframe{Algorithm for Computing Keys}
{
  Given 
  \begin{itemize}
  \item a relation $R(A_1, A_2, \ldots, A_n)$ and
  \item the set of all FDs $S$ that hold in $R$,
  \item compute all the keys of $R$. 
  \end{itemize}\pause
  \begin{enumerate}
  \item For every subset $K \subseteq \set{A_1, A_2, \ldots, A_n}$,
    compute \closure{K}.
  \item If $\closure{K} = \set{A_1, A_2, \ldots, A_n}$ and for every
    attribute $A$, $\closure{K - \set{A}} \not= \set{A_1, A_2, \ldots,
      A_n}$, then output $K$ as a key.
  \end{enumerate}
  \pause
  \begin{itemize}
  \item Running time of the algorithm is exponential in the number
    of attributes.
  \end{itemize}

}

\myframe{Armstrong's Axioms}
{
  \begin{itemize}
  \item We can use closures of attributes to determine if any FD follows
    from a given set of FDs.
  \item Armstrong's axioms: complete set of inference rules from which
    it is possible to derive every FD that follows from a given set:
    \pause
    \begin{description}
    \item[Reflexivity] If $\set{B_1, B_2, \ldots, B_m} \subseteq
      \set{A_1, A_2, \ldots, A_n}$, then \fd{A_1 A_2 \ldots
        A_m}{B_1B_2\ldots B_m} (Trivial FDs). \pause
    \item[Augmentation] If \fd{A_1 A_2 \ldots A_m}{B_1B_2\ldots B_m},
      then \fd{A_1 A_2 \ldots A_m C_1C_2\ldots C_k}{B_1B_2\ldots B_m
        C_1C_2\ldots C_k}, for any set of attributes \set{C_1, C_2,
        \ldots, C_k}. \pause
    \item[Transitivity] If \fd{A_1A_2\ldots A_n}{B_1B_2\ldots
        B_m} and \fd{B_1B_2\ldots B_m}{C_1C_2\ldots C_k} then
      \fd{A_1A_2\ldots A_n}{C_1C_2\ldots C_k}.
    \end{description}
  \end{itemize}

}


\myframe{Differences in Notation}
{
  \begin{description}
  \item[Relation schema] $R(A_1, A_2, A_3)$: parentheses surround
    attributes, attributes separated by commas.
  \item[Set of attributes] \set{A_1, A_2, A_3}: curly braces surround
    attributes, attributes separated by commas.
  \item[FD] \fd{A_1 A_2}{A_3}: no parentheses or curly braces,
    attributes separated by spaces, arrows separates left hand side and
    right hand side.
  \item[Set of FDs] \set{\fd{A_1 A_2}{A_3}, \fd{A_2}{A_1}}: curly braces
    surround FDs, FDs separated by commas.
  \end{description}

}

\section{Minimal Bases}

\myframe{Minimal Basis}
{
  \begin{itemize}
  \item A relation may have a large set of equivalent sets of FDs.
  \item If we are given a set $S$ of FDs, then any set of FDs that is
    equivalent to $S$ is called a \mydef{basis} of $S$. \pause
  \item We will limit ourselves to bases in which each FD has only one
    attribute on the right hand side. \pause
  \item A set $B$ of FDs is a \mydef{minimal basis} for a relation $R$
    if
    \begin{enumerate}
    \item Every FD in $B$ has one attribute on the right hand side.
    \item If we remove any FD from $B$, then the result is not a basis.
    \item If for any FD in $B$, we remove one or more attributes from
      the left hand side of the FD, then the result is not a basis.
    \end{enumerate}

  \end{itemize}
}

\myframe{Example of Minimal Basis}
{
  \begin{itemize}
  \item $R(A, B, C)$ is a relation such that each attribute functionally
    determines the other two attributes.
  \item What are the FDs that hold in $R$ and what are the minimal
    bases? (Assume only one attribute on the right-hand side, only
    non-trivial FDs) \pause
  \item FDs: \pause \fd{A}{B}, \fd{A}{C}, \fd{B}{A}, \fd{B}{C}, \fd{C}{A},
    \fd{C}{B}, \pause \fd{AB}{C}, \fd{BC}{A}, \fd{AC}{B}. \pause
  \item Minimal bases: \pause \set{\fd{A}{B}, \fd{B}{A}, \fd{B}{C},
      \fd{C}{B}}, \set{\fd{A}{B}, \fd{B}{C}, \fd{C}{A}}, and others.
  \end{itemize}
}




\end{document}

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 
