Databases & Storage · Paper 01 / 05

A Relational Model of Data for Large Shared Data Banks

E. F. Codd

1970 · Communications of the ACM · ~12 min read

Read the original paper

Codd defines data as relations related by shared values, so programs stop depending on how records are stored. Read it to see which failures the model was built to remove, and why it made the query optimiser necessary.

Picture a payroll program at a large company in 1969. The data lives in IBM’s IMS, a hierarchical database. Each department record sits at the top of a small tree, and its employee records hang beneath it, linked by pointers stored on disk. To list the engineers who earn more than 80,000, the program opens the ENG department record, follows the pointer to its first employee, checks the salary, follows the next pointer, checks again, and stops at the end of the chain. The program is a route through the storage.

Now the operations team wants to reorganise the file so that employees hang under projects instead of departments, because a new reporting system needs that. Every program that walks from department to employee stops working. Nobody changed what the data means. Asha still works in Engineering and still earns what she earned yesterday. Only the route changed, and the route was written into hundreds of programs.

Edgar Codd’s 1970 paper is about removing that route from the program. After reading it you should be able to say exactly which kinds of change used to break applications, why describing data as relations stops them breaking, and what the database had to take on in exchange. That last part, the cost, is the reason query optimisers exist.

Three ways a program depended on the disk

The paper does not open with tables. It opens with a diagnosis. Codd lists three ways that programs of his day depended on how data was stored, and each one is a specific failure an engineer at the time would have recognised.

The first is ordering dependence. If employee records are stored in name order, a program that prints the first employee whose salary exceeds 80,000 and stops is quietly relying on name order. Re-sort the file by employee number for a different application and the program still runs, but it prints a different person. The second is indexing dependence. If a program asks for records through a particular index, dropping that index to save space breaks it, even though the index was only ever a performance aid. The third, and the one that hurt most, is access path dependence: the program knows the shape of the tree or network, which record owns which, and navigates it.

dept: ENGemp: Ashaemp: Benemp: Eliproject: Atlas“find Eli’s salary” = start at the department, follow next-pointers until the name matchesthe program knows the pointers; change the layout and the program breaks
Reading data in a pointer database. To find Eli’s salary the program starts at the department and follows next-pointers until the name matches. The order of the chain is part of the program.

Codd makes the access path problem concrete with a small example of parts, projects and the commitments between them. He shows several different hierarchies that could hold exactly the same facts, parts above projects, projects above parts, and so on, and points out that a program written for one structure fails on the others. The facts are identical in every version. Only the storage shape differs, and the programs are tied to the shape.

This is worth reading slowly because it changes what the paper is about. The relational model is often taught as “data in tables”, as if the point were a tidy format. Codd’s point is separation: the programs should depend on what the data means, and the storage should be free to change underneath them. He calls this data independence, and everything else in the paper serves it.

What a relation is, and what it deliberately leaves out

A relation, in Codd’s definition, is a set of tuples. Each tuple takes one value from each of a fixed list of domains. Our running example has two relations:

employees(name, dept, salary)
  (Asha, ENG, 92)   (Ben, ENG, 71)   (Chen, OPS, 58)   (Dara, SALES, 64)

departments(dept, dept_name, floor)
  (ENG, Engineering, 4)   (OPS, Operations, 2)   (SALES, Sales, 1)

The interesting part of the definition is what it excludes. Because a relation is a set, its rows have no order, so no program can depend on order. Because it is a set, there are no duplicate rows, so every row must be identifiable by its values. And there are no pointers. Asha’s row does not point at the Engineering row. It contains the value ENG, and the departments relation contains a row whose key is ENG. The relationship is the shared value.

employeesnamedeptsalaryAshaENG92BenENG71ChenOPS58DaraSALES64departmentsdeptnamefloorENGEngineering4OPSOperations2SALESSales1join on dept = dept · the database decides how to find the match; the query just says what
The same facts as two relations. Nothing points at anything. Employees and departments are related because both contain the value ENG, and finding the matching rows is the database’s job.

Codd names the identifying columns too. A primary key is a domain, or combination of domains, whose values identify each row. When a relation carries a column whose values are the primary key of another relation, as employees.dept does, he calls it a foreign key. These terms appear in the 1970 paper and are still the words in every schema review.

Every one of these exclusions closes off one of the three dependencies. No order means no ordering dependence. No pointers visible to the user means no access path dependence. And since indexes are not part of the model at all, a program written against relations cannot name one, so indexes can be added and dropped freely. The storage engine is still allowed to keep records in name order, build indexes and even maintain pointer chains internally. It just cannot expose them.

Predict first

The operations team re-sorts the employees file by salary to speed up a payroll report. Two programs run against it: a navigational one that walks the ENG chain and stops at the first employee earning over 80, and a relational query that asks for the names of ENG employees with salary over 80. What happens to each?

Show the worked answer

The navigational program still runs and returns a person, but possibly a different one, because “first” now means “lowest salary over 80” instead of “first in name order”. Nothing fails loudly. That is the dangerous version of ordering dependence.

The relational query returns the same set as before: Asha. It never said “first”, so the new physical order cannot change its meaning. If the program wants the result in name order it must ask for that explicitly, which is what ORDER BY later became.

Flattening the data: the first normal form

Pointer databases happily stored repeating groups inside a record. Codd’s own example in the paper is an employee record that contains, inside it, a job history, and inside each job a salary history, and alongside those a list of children. That nesting is natural to draw, and it is exactly what makes the data hard to ask questions of: a query about salaries has to know it is reaching through jobs to get there.

Codd requires that every domain be simple, meaning a value is atomic and not itself a set or list. A relation that meets this is in what he calls normal form, later named first normal form. He then shows how to take the nested employee record and decompose it into several flat relations: one for employees, one for job history keyed by employee and job date, one for salary history keyed by employee, job date and salary date, one for children keyed by employee and child name. Each nested level becomes its own relation, and the key of the parent is carried down into the child so the pieces can be put back together by value.

Two things follow from this. The operators described next can treat every relation the same way, because there are no special cases for nested values. And redundancy becomes something you can see and reason about. The paper has a section on redundancy and consistency that distinguishes relations that can be derived from others from those that cannot, and frames consistency as a statement that must hold across relations. The further normal forms, second and third, came in Codd’s papers of the following years. The 1970 paper only plants the idea that a schema can be checked for redundancy the way a proof can be checked for a missing step.

Operations that take tables and return tables

If programs can no longer navigate, they need another way to ask. Codd defines a set of operations on relations whose result is always another relation. In the paper’s vocabulary these include projection (keep some columns, drop duplicates), restriction (keep the rows that satisfy a condition), join (combine two relations on equal values in a shared domain), composition and permutation. Because each result is a relation, the output of one operation can be the input of the next. A question becomes an expression.

Here is our query, “names of engineers on floor 4 earning more than 80”, written as a chain of those operations and then in the SQL that IBM’s System R team developed a few years later:

project[name]( restrict[salary > 80 and floor = 4]( employees JOIN departments ON dept ) )

SELECT e.name
FROM employees e JOIN departments d ON e.dept = d.dept
WHERE e.salary > 80 AND d.floor = 4;

Neither version mentions a pointer, an index or an order. Try it in the panel below: switch the join off and the floor column is simply unavailable, because the employees relation does not contain it and nothing in it points to where it lives.

Try itAsk a question of two tables

Filter rows, choose columns and decide whether to join. Note that you never say how to find anything: no pointers, no file offsets, no loop. The result is itself a table.

result · 6 rows
namedeptsalary
AshaENG92
BenENG71
ChenOPS58
DaraSALES64
EliENG55
FolaSALES83
the same question, two notations
algebra πname, dept, salary(employees ⋈ departments) SQL SELECT name, dept, salary FROM employees JOIN departments USING (dept);

The join matches rows by a shared value (dept) rather than by a stored link. Codd’s point: because tables relate by value, the storage engine may lay them out however it likes, and your query still means the same thing.

The paper also sketches a data sublanguage based on first-order predicate logic, in which a user states the properties of the rows wanted. Codd developed this into the relational calculus in a 1972 paper and showed that it and the algebra can express the same queries. That equivalence is what makes a declarative language possible: the user writes the description, and the system translates it into a sequence of operations it can execute.

The bill: someone now has to choose the route

Data independence moves the route out of the program. It does not make the route disappear. Take the query above and suppose employees has ten million rows and departments has fifty. The system could scan all of employees, filter by salary, and look up each survivor’s department. Or it could find the departments on floor 4 first, then use an index on employees.dept to fetch only their employees. If only one department sits on floor 4, the second plan reads a tiny fraction of the data. If most departments are on floor 4, the full scan may be cheaper because it reads the table sequentially.

In 1969 the programmer made that decision once, when writing the navigation. After Codd, the database has to make it for every query, using whatever it knows about the data. This is the job of the query optimiser, and the paper leaves a gap exactly its shape. Pat Selinger and colleagues filled it in System R with cost-based optimisation in 1979: estimate the cost of each candidate plan from statistics about the tables and pick the cheapest. An EXPLAIN plan today is that machinery showing its choice.

This was the strongest objection at the time, and it was a fair one. Charles Bachman, who built the network model and won the Turing Award in 1973 for it, argued that skilled programmers navigating a known structure would beat any general system. For a decade the critics were partly right, because early relational systems were slower. What changed the outcome was the optimiser getting good enough, and hardware getting fast enough, that the flexibility outweighed the overhead for most applications.

Change to storageNavigational programRelational queryWho absorbs the change
Re-sort the fileSilently returns different rows if it relied on orderSame result setNobody; order was never part of the meaning
Drop an indexFails if it navigated through that indexSame result, possibly slowerThe optimiser picks another plan
Restructure the hierarchyRewritten, since the route has changedSame resultThe storage layer and optimiser
Add a new kind of questionNew navigation codeA new expression over the same relationsThe query author, in a few lines

What later systems changed, and when to step away from the model

SQL did not implement Codd’s model faithfully, and the differences are worth knowing because they still cause bugs. Codd’s relations are sets. SQL tables and query results are bags: they allow duplicate rows unless you write DISTINCT or declare a key. SQL also added NULL with three-valued logic, in which NULL = NULL is not true. Codd himself proposed missing values in later work, but the specific behaviour engineers trip over, such as NOT IN returning nothing when the subquery contains a null, belongs to SQL.

The model also gave up something real: control over physical locality. A navigational database stored an order and its line items next to each other on disk because the parent record owned them. In a relational database they are two relations joined by value, and whether they are close on disk is the engine’s business. Clustered indexes, interleaved tables in Spanner and partition keys in distributed SQL systems are all ways of giving some of that control back without exposing it in queries.

That suggests when to revisit the decision. Document stores such as MongoDB nest an order’s line items inside the order, which is Codd’s nested employee record again. That is a reasonable choice when the access pattern is fixed and almost always “fetch this one thing whole”, and the price is the same one IMS users paid: a new question that cuts across the nesting needs new code or a second copy of the data. Wide-column stores like Bigtable, later on this list, go further and make the row key the only index. When the questions are unknown in advance or will change, the relational trade is still the one to make. Notice also that most of the NoSQL systems of the 2010s added a SQL-like query layer back on top within a few years.

How to read the original

The paper is about eleven pages and has no experiments, because it is an argument and a definition rather than a system. Read section 1.2, on data dependencies in present systems, first and carefully. It is the motivation, and the parts-and-projects example there shows the problem better than any summary. Then read 1.3 and 1.4 for the definition of a relation, keys and normal form, and follow the nested employee example through its decomposition with a pen.

Sections 1.5 and 1.6, on the sublanguage and on named versus stored relations, can be skimmed on a first pass. Section 2 defines the operations and then discusses redundancy and consistency. The notation is older than modern relational algebra courses and some operations, like composition and permutation, are not ones you will use, so read it for the idea that operations close over relations and that consistency is a property of the whole set of relations, not of one record. Instead of an evaluation, look for the places where Codd says what the system must now do on the user’s behalf. Those are the open problems the next twenty years of database research worked on.

The next paper on this list, ARIES, takes the relational system as given and asks a lower-level question: if the machine crashes in the middle of updating these relations, how does the database come back with every committed change and none of the uncommitted ones?