Skip to content

Commit

Permalink
Fix schema, relation and attribute representations (#51)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
MatBon01 authored Jun 15, 2023
1 parent 393f57a commit 69dd944
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
2 changes: 2 additions & 0 deletions report/.hunspell
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ secondmarker
counit
verticalcomposition
BagRelAlgOps
peopleSchema
peopleTuple
OLTP
DebitCredit
TPC
62 changes: 40 additions & 22 deletions report/background/relationalmodel.tex
Original file line number Diff line number Diff line change
@@ -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}

Expand Down Expand Up @@ -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}

Expand Down
6 changes: 4 additions & 2 deletions report/background/utils.sty
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@
\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}}}
\newcommand{\select}[2]{\ensuremath{\selectsymb{#1}\!\left(\relation{#2}\right)}}
\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
Expand Down

0 comments on commit 69dd944

Please sign in to comment.