Core CS · DBMS
Three descriptions of the same data
The rows never move when you draw this diagram. What moves is who is allowed to know how they are stored, and the two mappings in the middle are the reason a storage change does not become a code change.
Change the storage, watch the query survive →01 The idea
Three descriptions, one set of bytes
Take the five marks from the first lesson and put them in a real table: RESULT(sid, name, marks) holding Asha 78, Ravi 65, Meera 35, Kabir 82 and Nikhil 90. Three different people now have to talk about that table, and none of them wants to hear what the others have to say.
The exam office wants a list of students who passed. It does not want to know that Meera exists. The database designer wants to declare that sid is the primary key and that marks must lie between 0 and 100. She does not want to know which disk the file is on. The DBA has measured the query, found it reads every block of the file, and wants to reorganise the file so the marks sit in a tree. He does not want to know what a pass mark is. Each of the three is describing the same five rows, and each one needs a description that leaves the other two out.
So the data gets described three times, at three levels, and the DBMS stores a translation between each pair of neighbouring levels. That translation is the whole invention. Because the description of the tables never mentions a disk block, the DBA can change the blocks and only the translation below has to be rewritten. Nobody above notices. That property is what the architecture exists to deliver, and it has a name from the first lesson: data independence.
02 Worked example
The same five marks, described three times
Fix the details so there is something concrete to argue about. On disk, result.dat is a heap file: rows appended in insertion order, no index, one 8 KB block holding all five records. Each record is 24 bytes, laid out as sid in bytes 0 to 1, name in bytes 2 to 21, and marks in bytes 22 to 23. Five records is 120 bytes, so today the whole table fits inside that one block. The layout is the same layout at five million rows, which is what makes the DBA’s cost measurement worth acting on. The exam office reads a view, pass_list, defined as the name and marks of every student at or above the pass mark of 40.
Three rows, one set of bytes. 4E is 78 the moment something says bytes 22 and 23 are a SMALLINT, and 78 becomes a passing mark the moment something says 40 is the line. Nothing was copied between the rows. What changed is which description you are reading through. Now put the two translations in where they belong.
Read the two mapping boxes, not the three level boxes. The levels are the part students memorise; the mappings are the part interviews ask about. A request travels left to right, getting more physical at every step, and the answer travels back right to left, getting more abstract. The highlighted box is the one nobody names: it is the only place in the whole system that knows bytes 22 to 23.
That is worth saying twice, because it is the mechanism and not a slogan. The number 22 appears exactly once. It is not in the view definition, which names columns. It is not in the conceptual schema, which names types. It is not in the exam office’s query, which names pass_list. So when the DBA changes the file, there is exactly one thing to rewrite, and the DBMS owns it. Compare that with the pass mark of 40, which is written in the view definition by a person, and you can already feel which of the two mappings is going to be the awkward one.
03 Mechanics
What lives where, and what each mapping absorbs
Three tables, in the order an interviewer walks through them. The first is what is written down at each level. The fourth column is the one that matters: an abstraction is defined by what it hides, not by what it holds.
| Level | What is written down | Who writes it | What it hides, and from whom |
|---|---|---|---|
| Internal also called physical | file organisation, record layout and field offsets, block size, indexes, compression, file location | DBA, with the storage engine | That a row has an address at all. Nothing above the internal level knows a block exists. |
| Conceptual also called logical | tables, columns, types, primary and foreign keys, constraints, relationships | Database designer | How many bytes a row takes, whether an index exists, how fast anything is. The external level above it is told none of that. |
| External also called view | one named view per user group: chosen columns, chosen rows, derived columns | Application designer, per group | Rows, columns and whole tables that this group has no business seeing. No level sits above it, so what it hides, it hides from the user. |
Two neighbouring pairs means two mappings. Both are stored in the data dictionary, which is why both survive a restart and neither lives in your source code. Both also run in two directions: a request travels down through them and the answer travels back up, so a write issued at one level has to be translatable down to the level below as well.
| Mapping | What it translates | Stored as | Written by |
|---|---|---|---|
| External / conceptual | pass_list.name → a query over RESULT | the view definition | a person, by hand |
| Conceptual / internal | RESULT.marks → file, block, offset, access path | dictionary entries the storage engine maintains | the DBMS itself |
One kind of independence per mapping. The change column is what you actually do; the last column is why one of these is routine and the other is a project.
| Independence | Change you make | Must not change | How hard, and why |
|---|---|---|---|
| Physical | heap file → B+ tree file organisation keyed on marks; move the file; turn on compression; change block size | the conceptual schema, every external schema, every application | routine — one mapping is rewritten and the DBMS rewrites it. Nothing above ever named a block, so there is nothing above to update. |
| Logical | ADD COLUMN attempt; add a table; widen a type; split RESULT in two; drop a column | every external schema and every application above it | partial at best — the mapping above is written by hand and names tables and columns explicitly. Additive changes are absorbed. Splits must be rewritten by a person. Removals cannot be absorbed at all. |
The additive rule. Adding a column or a table is absorbed cleanly, because a view that names its columns explicitly cannot be disturbed by a column it does not name. That is the everyday case, and it is why logical independence looks easy until somebody renames something.
The SELECT * trap. A star defeats the mapping from both sides. PostgreSQL and MySQL expand * into a fixed column list when the view is created, so a later ADD COLUMN never shows up in the view and the exam office quietly keeps getting the old shape. An application that runs SELECT * against the base table instead does get the extra column, and code that unpacks a row into a fixed set of variables, or writes it into a fixed set of report columns, breaks on the day the column is added. Name your columns and both problems disappear.
Three levels, not three schemas. There is one internal schema, one conceptual schema, and as many external schemas as there are groups of users. Saying “a database has three schemas” is the single most common slip on this topic, and the follow-up is always to describe the schema for a second department.
05 Cheat sheet
The eight answers to get right
Every line here has a short answer that survives a follow-up and a shorter one that does not. The third column is the answer that sounds fine in the room and then costs you the next two minutes.
| Asked about | Say this | The answer that costs you |
|---|---|---|
| Internal schema | file organisation, record layout and offsets, block size, indexes, compression | “the physical level” — a restatement of the question. Name three things in it. |
| Conceptual schema | tables, columns, types, keys, constraints, relationships; one description for the whole database | “the logical design” — then say what is declared there and what is declared nowhere else. |
| External schema | one view per user group: chosen rows, chosen columns, derived columns | “what the user sees” — describe a view you would actually write, for a named group. |
| How many schemas | one internal, one conceptual, many external | “three” — there are three levels. The follow-up is the second department’s schema. |
| Conceptual / internal mapping | turns a conceptual request into a file, block, offset and access path | not mentioning it — the most common gap, and the one that makes the rest sound memorised. |
| External / conceptual mapping | turns a view request into a query over conceptual tables; it is the view definition | “the view” — the mapping is the definition, not the rows it returns. |
| Physical data independence | change the internal schema; conceptual schema and applications unchanged | “storage does not affect programs” — true and hollow. Name the mapping that absorbed it. |
| Logical data independence | change the conceptual schema; external schemas and applications unchanged | “the same, one level up” — it is not the same. It is the harder one, and you will be asked why. |
06 Where & why
Where the three levels are visible in real systems
This architecture is from an ANSI/SPARC report published in 1975, which makes students assume it is a diagram rather than a thing. In each system below you can point at a level or a mapping and say where it lives, and the last two are interesting because a level is missing or locked away. Naming one of these lands very differently from reciting the diagram.
CREATE VIEW pass_list AS SELECT name, marks FROM result WHERE marks >= 40 is the external / conceptual mapping, stored not computed. PostgreSQL hands it back with pg_get_viewdef; MySQL keeps it in information_schema.views. Both expand * to a column list when the view is created, so a star in a view definition freezes the shape at that moment.
Oracle names its storage layer separately from its tables: tablespaces, segments, extents and blocks. ALTER TABLE result MOVE TABLESPACE fast_ts relocates every row of the table and not one line of application SQL changes. What you do have to do afterwards is rebuild the indexes, which is the honest edge of physical independence: the mapping is rewritten for you, but rewriting it is not free.
SQLite gives you almost no control over storage: PRAGMA page_size, an index, and that is close to all of it. There are no tablespaces and no file layout to choose. Views exist, so the external level does. The lesson is that the internal level can be entirely private and the system is still a DBMS; the three levels are a division of responsibility, not three files you can open.
You can insert documents with no declared schema, so unless you add a JSON Schema validator the conceptual description lives only in the application. Indexes are still an internal decision you make without editing a query, so physical independence survives. Logical independence does not: when a field changes shape, every program that reads that field is the mapping, and there is no single definition to rewrite.
07 Interview questions
What they actually ask
This topic is asked as a diagram question and marked as a reasoning question. Nobody is impressed that you can list three levels. What they are listening for is whether you can classify a change, name the mapping that absorbs it, and say honestly where the architecture stops working.
What is the three schema architecture?
What exactly lives at the internal level?
How many schemas does a database have?
What are the two mappings, and where are they stored?
Define physical data independence, and give me a change that tests it.
Define logical data independence.
Why is logical data independence harder to achieve than physical?
Adding an index, adding a column, adding a report for the accounts office: which level is each?
Three schemas or three tiers, are they the same thing?
If the DBMS already gives me views, why do I need the conceptual level at all?
Give me a conceptual change that logical independence cannot absorb.
Do real systems actually achieve logical data independence?
08 Practice problems
Six to reason through
For every one, answer in the same order: which level is the change written down at, which mapping has to absorb it, and who does the rewriting. If you cannot name the mapping, you have not finished the question.