Translation to tables (n-ary relations)
We can consider Ampersand as a finite system of relations. Every relation is a set of pairs and each pair contains two atoms. Suppose we want to store that in a relational database. An obvious implementation would be to map every relation to a table. That yields a database filled with two-column tables. This gives rise to the following question: Can we store relations more efficiently?
This chapter studies ways to use database tables wider than two columns. The purpose is to get more efficient code by exploiting the strengths of relational databases. This translation must maintain the semantics of Ampersand in the eyes of its user. She may still perceive the world as a system of relations. All laws of relation algebra remain applicable in this world.
Let us look at an example to get a feeling for this translation. Consider the following table.
|1||Abraham||Lincoln||February 12, 1809|
|2||Barack||Obama||August 4, 1961|
|3||Calvin||Coolidge||July 4, 1872|
|4||Dwight||Eisenhower||October 14, 1890|
Since Ampersand works with relations, it must represent this table as relations. Three relations can do the job in the following manner:
POPULATION firstname[President*Name] CONTAINS [ ("1", "Abraham") , ("2", "Barack") , ("3", "Calvin") , ("4", "Dwight") ] POPULATION lastname[President*Surname] CONTAINS [ ("1", "Lincoln") , ("2", "Obama") , ("3", "Coolidge") , ("4", "Eisenhower") ] POPULATION birth[President*Date] CONTAINS [ ("1", "February 12, 1809") , ("2", "August 4, 1961") , ("3", "July 4, 1872") , ("4", "October 14, 1890") ]
Notice that the column names in the table correspond with the relation names in Ampersand. In the table we call them "attributes". So it makes sense to say that a relation in Ampersand can correspond with an attribute in a table.
- a set of concepts
- a set of relations
R. Every element of
r[P*Q], in which
ris called the name,
Pis called the source, and
Qis called the target.
- four predicates on relations,
- a set of tables
- a set of attributes
A. Every element of
a<t,c>, in which
ais called the name,
tis called the table, and
cis called the type.