In Novice Terms, How Does an Ordered Pair Relate to a Database Row (Tuple)?

222 Views Asked by At

Im putting a technical presentation for an interview (topic I chose). I am researching real-time data streaming. I am familiar with what an ordered pair is as it pertains to a graph i.e (x, y) defines a point on the x,y axis.

May you explain to me how this relates to columns in a database? Does this have to do with the index?

I'm trying to visualize this but all I can think about is result sets in the DBMS and want to learn how this applies.

Thanks

1

There are 1 best solutions below

3
On BEST ANSWER

The idea you're looking for is the relation. Relational databases are an application of the mathematical theory of relations.

If you have two sets, $A$ and $B$, you can form the set of all ordered pairs $(a, b)$ where $a \in A$ and $b \in B$. We call this set of ordered pairs the Cartesian product of $A$ and $B$, denoted $A \times B$. In other words

$$A \times B = \{(a,b) : a \in A, b \in B \}$$

For example if $A = B = \mathbb{R}$, then $A \times B = \mathbb{R} \times \mathbb{R} = \mathbb{R}^2$.

This is a set-theoretical way to think of the Cartesian plane as the product of the $x$- and $y$-axes.

Another example would be if $A = \{$apple, banana} and $B = \{$yellow, red} then

$A \times B =$ {(apple, yellow), (apple, red), (banana, yellow), (banana, red)}.

Now, what is a relation on $A$ and $B$? It's a subset of their Cartesian product.

For example if we wish to specify the relation "equals" on $\mathbb{R} \times \mathbb{R}$ we would specify the subset of $\mathbb{R}^2$ consisting of exactly those pairs $(x,y)$ for which $x = y$.

So you see that we can express a relation as a subset of a Cartesian product.

In our fruit/color database, the relation of interest is the set of ordered pairs representing each fruit and its actual color. This is represented by the subset {(apple, red), (banana, yellow)}.

The key point is that A relation between $A$ and $B$ is a subset of $A \times B$.

In the general case, suppose you have $n$ sets $S_1, S_2, \dots, S_n$. Then a relation on these $n$ sets is just a subset of the Cartesian product of all of them, where instead of ordered pairs, the Cartesian product is the set of all ordered n-tuples formed from the sets.

You can now see that if you have a database table representing the employees at a company, the data in the database is a subset of the Cartesian product of sets representing the employee name, employee number, job title, salary, years on the job, etc.

Once we choose a subset of that Cartesian product, we have a database table populated with the employees and their respective information.

The rest of relational database theory is worked out in terms of relational algebra on sets.

To sum this up: A relation is a subset of the Cartesian product of a collection of $n$ sets; each set representing a column in a database table. The contents of the database are a particular set of $n$-tuples, each $n$-tuple representing a row of the database table.