51/224
\begin{frame}
  \frametitle{Avoid Unnecessary Duplicate Elimination}
  
  \begin{goal}{Sufficient condition for superfluous \sql{distinct}}
    Assumption: \sql{where} clause is a conjunction (\sql{and}).

    \begin{enumerate}
    \medskip
    \item 
      Let $\mathcal{K}$ be the set of attributes in the \sql{select} clause.
    \medskip
      \item If $A~\sql{=}~c$ in the \sql{where} clause and $c$ a constant, add $A$ to $\mathcal{K}$.
      \item If $A~\sql{=}~B$ in the \sql{where} clause and $B \in \mathcal{K}$, add $A$ to $\mathcal{K}$.
      \item If $\mathcal{K}$ has a key of a variable $X$, add all attributes of $X$ to $\mathcal{K}$.
    \medskip
      \item Repeat 2, 3 and 4 until $\mathcal{K}$ is stable.
    \medskip
    \end{enumerate}
    If $\mathcal{K}$ \emph{contains a key of every tuple variable} 
    listed under \sql{from}, then \sql{distinct} is superfluous.
  \end{goal}
  \smallskip

  Intuition behind the algorithm: think of $\mathcal{K}$ as the
  set of attributes that are uniquely determined by the result.
\end{frame}