Search

Search papers and lessons

Network Data Model

Level 3 · 10 min read

The network data model stores records as nodes linked by owner-member sets, so one record can belong to several parents and many-to-many relations need no copying.

On this page

  • Colour = topic mix
  • Databases
  • Discrete math
  • Sign in to see your progress

TL;DR

The network data model stores records as nodes and connects them with named owner-member sets. A record may be a member of several sets, so it can have several parents at once. That lets a many-to-many relation, such as students and courses, be stored once per entity with link records between them, instead of copying either side. Finding related data means following the links, not searching.

Where you'll see it: in the CODASYL database standard of the 1970s, in mainframe systems that many banks and airlines ran for decades, and in the idea that a record graph with explicit pointers can be a database in its own right.

Intuition

The Hierarchical Data Model lesson uses a tree: each record has exactly one parent. Real data often does not fit a tree. A student takes several courses, and a course has several students. Put students at the top and each course gets copied under every student. Put courses at the top and each student gets copied under every course. Either way the same fact is written many times.

The network model fixes this by letting a record have more than one parent. Think of a record as a box and a set as a named pile that one owner box controls. An owner has many members in a set. A member can sit in several piles, each controlled by a different owner. A student box and a course box are both owners, and an enrolment box sits in one pile owned by a student and another pile owned by a course.

flowchart LR
    S1[Student: Ann] -- takes --> E1[Enrolment 1]
    S1 -- takes --> E2[Enrolment 2]
    C1[Course: Algebra] -- has --> E1
    C2[Course: Biology] -- has --> E2
    S2[Student: Ben] -- takes --> E3[Enrolment 3]
    C1 -- has --> E3

Each enrolment is stored once. It is a member of Ann's set and of Algebra's set at the same time. The network of arrows is the whole data model. Many-to-many relations are just nodes with two incoming owner links.

This was the design goal. In the 1960s data was stored on slow tape and disk, and programmers wrote code that walked pointers from record to record, because that was the fastest way to reach related data. The network model made that walk the official interface.

The math

A network database has a schema, which describes record types and set types, and an instance, which holds the actual records and links. Writing RR for the set of record types and SS for the set of set types, the schema is a directed Graph.

Definition: Network schema

A network schema is a pair (R,S)(R, S). Each element of RR is a record type with a list of fields. Each element s∈Ss \in S is a set type with an owner type o(s)∈Ro(s) \in R and a member type m(s)∈Rm(s) \in R. Viewed as a directed graph, the nodes are the record types and each set type is a directed edge from its owner type to its member type.

An instance assigns actual records to these types and actual links to these edges. For a set type ss, each owner record xx of type o(s)o(s) has an occurrence of ss: the ordered list of member records of type m(s)m(s) that xx controls. The rule that matters is this. A member record may belong to at most one occurrence of a given set type, but it may belong to occurrences of many different set types.

The result is a graph of records in which each record has at most one owner per set type. Write owns(v)\mathrm{own}_s(v) for the owner of record vv in set type ss. The constraint is

owns(v) is unique (or undefined) for each set type s and each member record v.\mathrm{own}_s(v) \text{ is unique (or undefined) for each set type } s \text{ and each member record } v.

Nothing forces the total number of owners to be one. So a record with kk set memberships has kk parents, and the structure is in general a directed graph, not a tree. The schema may even contain a cycle, for example when one set type runs from record type A to B and another from B back to A. (The CODASYL specification did not allow a set type to have the same record type as both owner and member.)

Cost of following a set

CODASYL implemented an occurrence as a linked list of member records, with pointers from the owner to the first member and from each member to the next. If an owner has kk members in a set type, listing them takes O(k)O(k) pointer follows and needs no search. Finding the owner of a given member takes one follow when the set is declared with owner pointers, which CODASYL made an option.

For an instance with msm_s member records in set type ss, the number of owner-member links is ∑sms\sum_s m_s, since each member record of each set contributes one link. Every enrolment in the example below contributes one link per set it belongs to, so the count of links grows with the number of memberships, not with the number of distinct entities.

Worked examples

Example
Small graph: Ann, Algebra and one enrolment

Use the diagram with one student, one course and one enrolment record EE.

  1. Let the set types be takes (owner Student, member Enrolment) and has (owner Course, member Enrolment).
  2. Record EE is a member of Ann's occurrence of takes. Its owner in that set is Ann, so owntakes(E)=Ann\mathrm{own}_{\mathrm{takes}}(E) = \text{Ann}.
  3. Record EE is also a member of Algebra's occurrence of has, so ownhas(E)=Algebra\mathrm{own}_{\mathrm{has}}(E) = \text{Algebra}.
  4. Ask for all courses of Ann. Start at Ann, walk her takes occurrence to reach EE, then take EE's has owner pointer to reach Algebra. That is one list walk and one pointer follow.

Answer: Algebra. Interpretation: the enrolment record is the only place the relation is stored, and it is reached from either side by a pointer.

Example
Storage for 100 students, 20 courses, 500 enrolments

Illustrative numbers. Each student takes 5 courses, so there are 100×5=500100 \times 5 = 500 enrolments.

  1. Records: 100 students, 20 courses and 500 enrolments, a total of 100+20+500=620100 + 20 + 500 = 620 records. No course or student is copied.
  2. Set memberships: each enrolment belongs to two set occurrences, one takes and one has. So there are 500×2=1000500 \times 2 = 1000 member links.
  3. Average size of a course occurrence: 500/20=25500 / 20 = 25 enrolments per course. Walking one course's occurrence visits 25 member records.
  4. Compare with the tree rooted at students, where the 500 course records would be copies. The network model stores 20 course records and avoids the 480 extra copies.

Interpretation: the network model stores the relation once, at the cost of one link record per enrolment and two pointers each. Updating a course name touches one record.

Example
A list query: who takes Algebra?

Using the same numbers, suppose Algebra has 25 enrolments.

  1. Start at the Algebra owner record.
  2. Walk its has occurrence: 25 member records, one per enrolment. This is O(25)O(25) steps.
  3. For each enrolment, follow its takes owner pointer to the student. That is 25 more pointer follows.
  4. Collect the 25 student records.

Interpretation: the query costs time proportional to the size of the answer and the set, and no search is needed. The price is that the program must know which set to walk. A new kind of question, such as "which courses have more than 30 students", has no ready-made set and requires a program that walks every course occurrence.

Tradeoffs and failure modes

The network model is a direct answer to many-to-many data and to fast navigation. It is also rigid and hard to use without knowing the schema in detail.

SituationProblemBetter choice
Many-to-many relations and fast navigation along known pathsThe model handles this well, with one stored link per membershipKeep the network model, or use a graph store with explicit edges
Ad hoc queries that were not planned into the schemaEach new question needs a program that walks the right setsUse a relational model with a declarative query language such as SQL
The schema changesAdding a set type or changing an owner means rewriting the navigation codeRelational schemas and migrations change more easily
Applications need to be insulated from storage layoutThe programmer sees pointers and set names, so storage details leak into codeUse Data Independence, where queries name fields and the engine picks the path
Searching by a field valueWithout a secondary index, the program scans every recordAdd indexes, as described in Database Index

The core failure mode was the program that navigated the database by hand. Changing the physical layout could break every such program, which is why the relational model's separation of logical schema from physical storage became so influential.

History

Charles Bachman developed the Integrated Data Store (IDS) at General Electric in the early 1960s. It was one of the first database systems to let programs navigate records through explicit links. Bachman received the ACM Turing Award in 1973, in part for this work on database technology.

The Conference on Data Systems Languages (CODASYL) formed a Database Task Group that proposed a standard for the network model. Its 1969 report, and the revisions that followed, defined record types, set types, and a navigational language for programs. The model became known as the CODASYL or DBTG model and was adopted by many mainframe vendors.

It caught on because it was faster than the alternatives of the time for the workloads that businesses had: large, stable schemas and known access patterns. Banks, airlines and manufacturers built large systems on it, and many of those systems ran for decades.

Its decline came from the relational model proposed by Edgar F. Codd in 1970. The Relational Model let a user state a question declaratively and let the system choose how to answer it. As hardware improved and query optimisers matured, the flexibility of relations outweighed the speed of navigation for most applications. The network model survives as the conceptual ancestor of graph databases.

Check yourself

QuestionIn a network schema, can a member record have more than one owner? Explain using set types.Show answer

Yes. A member record can belong to occurrences of several set types, and each set type gives it at most one owner. So a record can have one owner per set type, which is several owners in total. This is what lets a student and a course both own the same enrolment record.

QuestionAn enrolment is a member of two set occurrences, `takes` and `has`. How many owner-member links does one enrolment contribute to the instance?Show answer

Two. Each set membership is one owner-member link, and the enrolment has one membership in takes and one in has. In the example with 500 enrolments, the total is 500×2=1000500 \times 2 = 1000 links.

QuestionWhy does a network schema stop being a tree when a record can belong to two set types?Show answer

A tree requires every node except the root to have exactly one parent. If a record has two owners, it has two parents, so the structure has at least one node with two incoming edges. That is a graph, and it need not have a single root.

QuestionSuppose a course has 40 enrolments and you want the names of all its students. Describe the steps and count the pointer follows.Show answer

Start at the course owner record and walk its has occurrence, visiting 40 enrolment members. For each enrolment, follow its takes owner pointer to the student, which is 40 follows. Total: 40 member visits and 40 owner follows, so about 80 pointer operations, with no search.

QuestionA business wants a report of all courses with more than 30 students, and the schema has only the `has` and `takes` sets. Why is this awkward, and what would make it easy?Show answer

The schema organises records around owners, so the query must visit every course occurrence and count its members. That is a full pass over the courses, which is linear in the number of courses and enrolments. It is easy in a relational system, where a single declarative query with a group-by and a having clause expresses it, and the engine chooses an efficient plan.

Sources