[DMDB] Completed normal forms, start query optimization

This commit is contained in:
2026-06-30 16:21:35 +02:00
parent 4b4b74fcb6
commit 59e4bcd5e9
19 changed files with 168 additions and 13 deletions
@@ -0,0 +1,32 @@
\subsubsection{Search Space}
To create the search space, the optimizer splits a query into a collection of query blocks,
where each query block has one \texttt{SELECT} and \texttt{FROM} clause and \textit{at most} one \texttt{WHERE}, \texttt{GROUP BY} and \texttt{HAVING} clause.
Query plans are typically drawn up as trees, as they are typically easier to understand that way than as both SQL query or in relational algebra notation.
In addition, the query parser commonly transforms it into a tree-like data structure, so thinking about query plans in this way is a good habit.
For the symbols used here, see section \ref{sec:relational-algebra}.
\begin{center}
\begin{forest}
for tree={
ellipse,
inner sep=1mm,
s sep=10mm,
l sep=3mm
}
[$\Pi_{\texttt{s.PersNr}, \texttt{t.Grade}}$
[$\bowtie_{\texttt{t.LectureID = l.LectureID}}$
[$\bowtie_{\texttt{s.PersNr = t.PersNr}}$
[$\Sigma_{\texttt{s.semester < 5}}$
[\texttt{Student}]
]
[\texttt{Test}]
]
[$\Sigma_{\texttt{l.Name = 'Databases'}}$
[\texttt{Lecture}]
]
]
]
\end{forest}
\end{center}
@@ -0,0 +1,21 @@
\paragraph{Rewriting Rules}
Given a logical plan as above, there are multiple ways in which we can construct a physical plan.
We can use different join orders, decide when selection happens and specific implementations of operators.
The following rules were discussed in the lectures:
\begin{enumerate}[label=\textbf{R\arabic*}]
\item Conjunctive selection operators can be deconstructed into a sequence of individual selections:
\[
\sigma_{\theta_1 \land \theta_2} = \sigma_{\theta_1}(\sigma_{\theta_2}(E))
\]
This is useful to split selections to push them earlier in the execution plan (reduces the number of elements to process subsequently)
\item Selection operators are commutative:
\[
\sigma_{\theta_1}(\sigma_{\theta_2}(E)) = \sigma_{\theta_2}(\sigma_{\theta_1}(E))
\]
This is useful to allow to first put the one that e.g. has an index.
\item Only the last in a sequence of projections is needed, others can be omitted
\[
\Pi_{t_1}(\Pi_{t_2}(E)) = \Pi_{t_1}(E)
\]
\end{enumerate}