56/224
\begin{frame}
  \frametitle{Avoid Unnecessary Duplicate Elimination}
  
  \begin{code}{\textwidth}{}
    \small
    \BUseVerbatim{query}
  \end{code}
  \ \\[.5ex]
  
  Let us assume that $\{\, \sql{first},\; \sql{last} \,\}$ is a key for \sql{Students}.
  
  \begin{enumerate}
  \pause
  \item Initialise $\mathcal{K} = \pause \{\, \sql{S.first},\; \sql{S.last},\; \sql{R.number},\; \sql{R.points} \,\}$.
  \pause
  \item [2.] $\mathcal{K} + \{\, \sql{R.category} \,\}$ because of $\sql{R.category = \textquotesingle{}homework\textquotesingle{}}$
  \pause 
  \item [4.] $\mathcal{K} + \{\, \sql{S.sid},\; \sql{S.address} \,\}$ since $\mathcal{K}$ contains a key of \sql{Students}
  \pause 
  \item [3.] $\mathcal{K} + \{\, \sql{R.sid} \,\}$ because of the conjunct \sql{S.sid = R.sid}
  \end{enumerate}
  \pause
  Finally, $\mathcal{K}$ contains a key of 
  \begin{itemize}
    \item \sql{Students S} $\{\, \sql{S.first},\; \sql{S.last} \,\}$ and
    \item \sql{Results R} $\{\, \sql{R.sid},\; \sql{R.cat},\; \sql{R.eno} \,\}$
  \end{itemize}
  \pause
  Thus \sql{distinct} is superfluous.
  
  \pause
  \begin{alertblock}{}
    If $\{\, \sql{first},\; \sql{last} \,\}$ is not key of \sql{Students}, the test would fail.\\
    Rightly so, since then the result could contain duplicates.
  \end{alertblock}
\end{frame}