A DBMS is built as a stack of layers, and each one narrows its job to a single problem.
At the top sits the query processor. It parses your SQL, checks that the tables and columns exist, and turns the statement into a plan the engine can run.
Under that sits the optimizer. It picks between several ways to execute the same statement, using the statistics it holds about the data.
Below the optimizer is the storage engine. It owns the files, the indexes, the pages and the write ahead log. It turns logical row operations into physical page operations.
Below all of that sit the operating system and the disk.
The separation matters because each layer can change without rewriting the one above it. When you add an index, the storage engine changes. The query processor never finds out.
-- Conceptual level: the two tables that model the business.
CREATE TABLE customers (
id INTEGER PRIMARY KEY,
full_name TEXT NOT NULL,
city TEXT NOT NULL
);
CREATE TABLE orders (
id INTEGER PRIMARY KEY,
customer_id INTEGER NOT NULL REFERENCES customers(id),
total REAL NOT NULL
);
INSERT INTO customers (id, full_name, city) VALUES
(1, 'Asha Rao', 'Chennai'),
(2, 'Ben Das', 'Pune');
INSERT INTO orders (id, customer_id, total) VALUES
(10, 1, 450.0),
(11, 2, 1290.5);
-- Internal level: a physical structure added for the storage engine.
CREATE INDEX idx_orders_customer ON orders(customer_id);
-- What the engine actually stored on disk.
SELECT type, name, tbl_name FROM sqlite_master ORDER BY type, name;
-- Query processor and optimizer: one statement, one chosen plan.
SELECT c.full_name, c.city, SUM(o.total) AS lifetime_value
FROM customers c
JOIN orders o ON o.customer_id = c.id
GROUP BY c.id
ORDER BY lifetime_value DESC;
The customers and orders tables sit at the conceptual level. The join and the grouping are the query processor at work.
The index on customer_id is the storage engine at work. It gives the engine a fast way to find the matching orders.
The statement against sqlite_master reads the file catalog, which is the closest a small engine comes to showing you pages on disk.
The final query returns two rows. Ben Das comes first with 1290.5, and Asha Rao follows with 450.0.
The separation exists so the part that understands the question and the part that owns the bytes never need each other's details.
The query processor works with tables, columns and predicates. The storage engine works with pages, slots and byte offsets. Mix them together and every new storage format becomes a rewrite of the query layer. Every new SQL feature becomes a change to the file format.
Here is what breaks when the boundary is not respected.
The first problem is that the optimizer loses its inputs. A good plan needs to know how many rows a table holds and how the values are spread. That knowledge lives with the storage engine. When it never crosses the boundary, the optimizer guesses. A guess means a full table scan where an index lookup would have done the job.
The second problem is that recovery gets tangled with query logic. Writing pages, flushing the log and replaying a crash belong to the storage engine. When they are mixed in, it becomes hard to tell which changes were durable and which were lost. That is where silent data loss starts.
The third problem is concurrency. Readers and writers negotiate through the storage layer, not through SQL. Mixing the two makes it impossible to reason about a lock, and a lock you cannot reason about becomes a deadlock.
The fourth problem is testing. A clean boundary lets the query layer be tested against fake storage, and the storage layer against a fake query. Without it, every test needs a real disk.
The practical lesson for an interview is simple. When a database is slow, ask which layer is at fault. A bad plan is a query processor problem. A slow read is a storage engine problem. The two need different fixes, and mixing them up wastes weeks.