From 69dd944245c5b7dfc185a19ac72ef308728b3a30 Mon Sep 17 00:00:00 2001 From: Matteo Bongiovanni <40599507+MatBon01@users.noreply.github.com> Date: Thu, 15 Jun 2023 15:06:33 +0100 Subject: [PATCH] Fix schema, relation and attribute representations (#51) Changes also include preliminary editing of the relational model section. * Fix todo in relational model introduction * Fix relation and attribute styles * Fix schema definition * Change relation and attribute font * Proof read the definition of schema * Proof read the definition for a tuple * Add some labels to dictionary --------- Signed-off-by: Matteo Bongiovanni <40599507+MatBon01@users.noreply.github.com> --- report/.hunspell | 2 + report/background/relationalmodel.tex | 62 +++++++++++++++++---------- report/background/utils.sty | 6 ++- 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/report/.hunspell b/report/.hunspell index 641bb79..dd0b42f 100644 --- a/report/.hunspell +++ b/report/.hunspell @@ -35,6 +35,8 @@ secondmarker counit verticalcomposition BagRelAlgOps +peopleSchema +peopleTuple OLTP DebitCredit TPC diff --git a/report/background/relationalmodel.tex b/report/background/relationalmodel.tex index 7054e96..dc79024 100644 --- a/report/background/relationalmodel.tex +++ b/report/background/relationalmodel.tex @@ -1,50 +1,68 @@ \section{The relational model of a database}\label{sec:relationalmodel} -We briefly describe the relational model of a database so that we can introduce the key operators we are modelling using category theory. \todo{not modelling, think of better word} +We briefly describe the relational model of a database so that we can introduce +the key operators we seek to describe using category theory. \subsection{Introduction to the relational model} There are several different data models to choose from when designing a database that specify important aspects of the design such as the structure, operations and constraints on the data \cite{DatabaseSystems}. For this project we concern ourselves with the relational model and its associated algebra. -The relational model represents data through two dimensional tables, called \emph{relations}. Each relation contains several \emph{attributes}, denoting the columns of the table. We call the name of the relation and the set of its attributes a \emph{schema} and they are denoted by the name of the relation followed by the set of attributes in parentheses.\cite{DatabaseSystems} For instance: +The relational model represents data through two dimensional tables, called +\emph{relations}. The columns of the ``table'' are called its \emph{attributes} +and the name of the relation with the set of its attributes is its +\emph{schema} \cite{DatabaseSystems}. We denote the schema of a relation +\relation{R} with attributes $\attribute{A_1}, \attribute{A_2}, \ldots, +\attribute{A_n}$ as: \begin{center} -\begin{verbatim} - R(a1, a2,..., an) -\end{verbatim} + \schema{\relation{R}}{\attribute{A_1}, \attribute{A_2}, \ldots, + \attribute{A_n}} \end{center} -is a relation \relation{R} with $n$ attributes \attribute{a1}, \attribute{a2}, \ldots, \attribute{an}. A more practical example is the schema -\begin{figure}[!h] -\begin{verbatim} - People(firstName, surname, age) -\end{verbatim} -\caption[Schema for the \relation{People} relation]{Example of a schema for the relation \relation{People}} -\label{fig:peopleSchema} + + +A more practical example is the schema found in \fref{fig:peopleSchema}. +It describes the schema for the relation \relation{People} with the attributes \attribute{firstName}, \attribute{surname} and \attribute{age}. +An (empty) tabular representation for the \relation{People} relation can be found on \fref{tab:peopleRelationHeadings}. + +\begin{figure}[h] + \centering + \schema{\relation{People}}{\attribute{firstName},\ \attribute{surname},\ + \attribute{age}} + \caption[Schema for the \relation{People} relation]{Example of a schema for the relation \relation{People}} + \label{fig:peopleSchema} \end{figure} -This describes a schema for the relation \relation{People} and the attributes \attribute{firstName}, \attribute{surname} and \attribute{age}. -An empty table showing the relation can be found on \fref{tab:peopleRelationHeadings}. -\begin{table}[h] + +\begin{table}[t] \centering \begin{tabular}{l|l|l} \attribute{firstName} & \attribute{surname} & \attribute{age} \\ \hline\hline & &\\ \end{tabular} - \caption[\relation{People} relation's headings]{A tabular representation of the \relation{People} relation's attributes.} + \caption[\relation{People} relation's headings]{A tabular representation of the \relation{People} relation.} \label{tab:peopleRelationHeadings} \end{table} -A row of the table\footnote{Excluding the row with the headings.} is called a \emph{tuple} and it consists of \emph{components}, one per attribute. A tuple is simply denoted by a comma separated list of its components within parentheses. For instance a tuple for the \relation{People} relation would be: +A row of the table\footnote{Excluding any row representing the name of the +attributes} is called a \emph{tuple} which consists of \emph{components}, one +per attribute. A tuple is simply denoted by a comma separated list of its +components within parentheses. For instance a tuple for the \relation{People} +relation could be: \begin{figure}[!h] \centering - (\verb|Jim|, \verb|Smith|, 32). + (Jim, Smith, 32). + \caption{An example tuple in the \relation{People} relation.} + \label{fig:peopleTuple} \end{figure} -With this table we can now represent the \relation{People} in a tabular form in \fref{tab:peopleRelationWithTuple}: -\begin{table}[h] +We can now represent the \relation{People} relation containing the tuple in +\fref{fig:peopleTuple} as \fref{tab:peopleRelationWithTuple}. + +\begin{table}[b] \centering \begin{tabular}{l|l|l} \attribute{firstName} & \attribute{surname} & \attribute{age} \\ \hline\hline Jim & Smith & 32\\ \end{tabular} - \caption[\relation{People} relation with tuple]{A tabular representation of the \relation{People} relation and its associated tuple.} + \caption[\relation{People} relation with tuple]{A tabular representation of + the \relation{People} relation with a tuple.} \label{tab:peopleRelationWithTuple} \end{table} @@ -116,7 +134,7 @@ \subsubsection{Selections} \caption[Example of selection on \relation{People} relation]{People relation with the selection \select{\attribute{age}\:>\:30}{People} applied to it.} \label{tab:peopleRelationSelection} \end{table} -b + \subsubsection{Products}\label{sec:products} The product of two relations \relation{R} and \relation{S} is simply the Cartesian product of the set of tuples of each relation, where instead of a binary tuple of tuples, the result is a single longer tuple. Typically, the result of $\relation{R} \times \relation{S}$ has the elements of tuples in $R$ before those in $S$. \cite{DatabaseSystems} diff --git a/report/background/utils.sty b/report/background/utils.sty index 21b8066..2408541 100644 --- a/report/background/utils.sty +++ b/report/background/utils.sty @@ -43,8 +43,8 @@ \newcommand{\finitemap}[2]{\ensuremath{\mathrm{Map}_*\ #1\;#2}} % Relational model -\newcommand{\relation}[1]{\ensuremath{\mathrm{#1}}} -\newcommand{\attribute}[1]{\ensuremath{\mathnormal{#1}}} +\newcommand{\relation}[1]{\ensuremath{\mathtt{#1}}} +\newcommand{\attribute}[1]{\ensuremath{\mathtt{#1}}} \newcommand{\projsymb}[1]{\ensuremath{\pi_{#1}}} \newcommand{\proj}[2]{\ensuremath{\projsymb{#1}\!\left(\relation{#2}\right)}} \newcommand{\selectsymb}[1]{\ensuremath{\sigma_{#1}}} @@ -52,6 +52,8 @@ \newcommand{\natjoin}[2]{\ensuremath{\relation{#1}\bowtie\relation{#2}}} \newcommand{\thetajoin}[3]{\ensuremath{\relation{#2}\bowtie_{#1}\relation{#3}}} \newcommand{\equijoin}[4]{\ensuremath{\relation{#1}\,{}_{#2}\!\bowtie_{\:#4}\relation{#3}}} +% note no \relation or \attribute commands +\newcommand{\schema}[2]{\ensuremath{\mathtt{#1\left(#2\right)}}} % Temporary function to show italicised code similar to maths % TODO: Change