Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Database Management Systems (DBMS)  Module 1 – Foundations: what a DBMS does and how it works

Inside a database engine: the life of a query

Follow one SQL query through the parser, planner, executor, buffer manager and storage of SQLite and PostgreSQL, and read its plan and its bytecode.

  • Beginner
  • 35 minutes
  • Examples run with sql.js 1.14.2 and Python 3.14.8
  • By MySmartCoPilot
Free core, Pro depth: 7 of 35 minutes free
Free: A query reaches rows through cooperating stages. With a pass: 3 in-depth parts and 3 interview answers, about 28 minutes.

What you will learn

  • Trace a query through parser, rewriter, planner, executor, access methods, buffer manager and storage
  • Contrast an embedded engine (SQLite) with a client-server engine (PostgreSQL) and their process models
  • Read a SQLite query plan and its bytecode, and a PostgreSQL plan at a basic level
  • Check the exact engine versions your lab uses and explain why browser and local versions differ

Before you start

What you’ll learn · Before you start

What you will learn

  • Trace a query through parser, rewriter, planner, executor, access methods, buffer manager and storage
  • Contrast an embedded engine (SQLite) with a client-server engine (PostgreSQL) and their process models
  • Read a SQLite query plan and its bytecode, and a PostgreSQL plan at a basic level
  • Check the exact engine versions your lab uses and explain why browser and local versions differ

Before you start

On this page

The college query returns five students from eight students and fourteen enrolments. A database engine produces those rows by parsing and resolving SQL, planning access paths, executing the plan and retrieving required pages through buffers and storage.

Read the result, its chosen join order and the separate database bytecode: An instruction program prepared by an engine such as SQLite to implement a statement through its bytecode virtual machine.. The stages distinguish a grammar error, an absent name, a bad row and a slow execution; SQLite performs them inside an application, while PostgreSQL serves queries through its own processes.

A query reaches rows through cooperating stages

The query parser: The part of an engine that recognises the grammar of a SQL statement and forms a representation for later preparation. reads SQL grammar, then name resolution checks tables and columns against the catalog. A grammatical statement can therefore fail before it runs if a table name is absent. A view supplies its defining query to compilation or rewriting rather than an independent copy of result rows.

The query planner: The engine component that chooses access paths and operation order using estimates of the work needed to produce the requested result. chooses access paths and loop order from its statistics. The two complete college queries below write their joins differently, yet SQLite chooses the same nested loops. The query executor: The engine component that follows the chosen plan to produce rows, using the underlying access methods. follows that plan to return rows; it obtains table or index rows through the database access method: An engine operation for reading or changing table or index rows through their storage structure..

The buffer manager: The engine component that keeps database pages in memory and supplies a held page or fetches a missing one from storage. supplies required pages already held in memory. A missing page needs a storage read before the access method can continue, so the same plan can run differently with warm and cold pages. Locks and the log or journal coordinate concurrent work and recovery around this path.

The whole structure is drawn first; step through the request and the returned rows after reading it:

A query passes the parser, rewriter, planner and executor; rows come from access methods, the buffer manager and storage.SQL text from your programParserchecks the syntax, then the namesagainst the catalogRewriterreplaces views with their tablesPlannerchooses indexes and join orderfrom statisticsExecutorruns the plan, returns the rowsAccess methodsscan tables, search indexesBuffer managerkeeps recent pages in memoryStoragepages in files on diskasks for rowsasks for pagesreads pages it does not hold

The life of a query inside a database engine

Text description of the diagram

The diagram is one column of boxes, from the SQL text a program sends at the top to the storage on disk at the bottom.

  1. SQL text from your program goes to the parser, which checks the syntax, then the names against the catalog.
  2. The rewriter replaces views with the tables they read.
  3. The planner chooses indexes and the join order from statistics.
  4. The executor runs the plan and returns the rows to the program.
  5. The executor asks the access methods for rows; they scan tables and search indexes.
  6. The access methods ask the buffer manager for pages; it keeps recently used pages in memory.
  7. The buffer manager reads from storage, the pages in files on disk, only the pages it does not already hold.
Interactive · stage by stage A college query crosses the cooperating stages Follow SQL text down to required pages and then back to the five result rows.
A college query crosses the cooperating stages, step 8 of 8. Showing Parse and resolve, Rewrite, Choose a plan, Execute, Access rows, Find pages, Read missing pages. In focus: Execute.Parse and resolveRewriteChoose a planExecuteAccess rowsFind pagesRead missing pages

The drawing shows the whole scene; its 8 steps are listed below.

Every step as text
  1. Start from the college query. The complete college data has 4 departments, 8 students, 5 courses and 14 enrolments. The query asks for students enrolled in CS301, with their departments.
  2. Read grammar and names. The engine parses SQL and resolves its names against the catalog. Invalid syntax and absent names stop preparation before a valid row operation can run.
  3. Resolve a view when present. A view reference introduces its stored query. PostgreSQL has a rewrite subsystem; SQLite considers subqueries during statement compilation.
  4. Choose access and loop order. The planner chooses access paths and join order rather than following the written FROM order blindly. In this record, the course-code lookup is the outer loop.
  5. Request and return rows. The executor follows the chosen plan. It requests table or index rows through the access methods rather than treating every operation as a direct disk read.
  6. Find the required pages. The buffer manager supplies pages already in memory. A page that is absent needs a storage read before the access method can continue.
  7. Read only missing pages. Storage holds the database pages in files. Its read supplies the missing page to the buffer manager, not a new logical definition of the query.
  8. Return the complete result. The CS301 result contains Asha, Farah, Lakshmi, Meera and Ravi with their departments, ordered by name. Both differently written joins have the same complete recorded plan.

The data contains four departments, eight students, five courses and fourteen enrolments. Read all five returned CS301 names and both plans:

The college database, one query and its plan SQL · college.sql
-- A small college database: departments, students, courses and who is enrolled in what.
CREATE TABLE departments (
  dept_id INTEGER PRIMARY KEY,
  name    TEXT NOT NULL UNIQUE
);
CREATE TABLE students (
  student_id INTEGER PRIMARY KEY,
  name       TEXT NOT NULL,
  dept_id    INTEGER NOT NULL REFERENCES departments (dept_id),
  year       INTEGER NOT NULL CHECK (year BETWEEN 1 AND 4)
);
CREATE TABLE courses (
  course_id INTEGER PRIMARY KEY,
  code      TEXT NOT NULL UNIQUE,
  title     TEXT NOT NULL,
  credits   INTEGER NOT NULL
);
CREATE TABLE enrolments (
  student_id INTEGER NOT NULL REFERENCES students (student_id),
  course_id  INTEGER NOT NULL REFERENCES courses (course_id),
  grade      TEXT,
  PRIMARY KEY (student_id, course_id)
);

INSERT INTO departments VALUES
  (1, 'Computer Science'), (2, 'Electronics'), (3, 'Mechanical'), (4, 'Civil');
INSERT INTO students VALUES
  (1, 'Asha', 1, 3), (2, 'Ravi', 2, 3), (3, 'Meera', 1, 2), (4, 'Kiran', 3, 3),
  (5, 'Farah', 1, 3), (6, 'Joseph', 4, 2), (7, 'Lakshmi', 2, 2), (8, 'Arjun', 1, 4);
INSERT INTO courses VALUES
  (1, 'CS301', 'Database Systems', 4), (2, 'CS302', 'Operating Systems', 4),
  (3, 'EC201', 'Signals and Systems', 3), (4, 'MA201', 'Probability', 3),
  (5, 'HS101', 'Technical Writing', 2);
INSERT INTO enrolments VALUES
  (1, 1, 'A'), (1, 2, 'B'), (2, 1, 'B'), (2, 3, 'A'), (3, 1, NULL), (3, 4, 'A'), (4, 4, 'C'),
  (5, 1, 'A'), (5, 5, 'B'), (6, 4, 'B'), (7, 3, 'A'), (7, 1, NULL), (8, 2, 'A'), (8, 5, 'A');

-- Who is enrolled in Database Systems, and in which department?
SELECT s.name, d.name AS department
FROM courses AS c
JOIN enrolments AS e ON e.course_id = c.course_id
JOIN students AS s ON s.student_id = e.student_id
JOIN departments AS d ON d.dept_id = s.dept_id
WHERE c.code = 'CS301'
ORDER BY s.name;

-- How SQLite plans to run the same query.
EXPLAIN QUERY PLAN
SELECT s.name, d.name AS department
FROM courses AS c
JOIN enrolments AS e ON e.course_id = c.course_id
JOIN students AS s ON s.student_id = e.student_id
JOIN departments AS d ON d.dept_id = s.dept_id
WHERE c.code = 'CS301'
ORDER BY s.name;

-- The same query with the tables written in another order.
EXPLAIN QUERY PLAN
SELECT s.name, d.name AS department
FROM enrolments AS e
JOIN students AS s ON s.student_id = e.student_id
JOIN departments AS d ON d.dept_id = s.dept_id
JOIN courses AS c ON c.course_id = e.course_id
WHERE c.code = 'CS301'
ORDER BY s.name;

Output

┌─────────┬──────────────────┐
│  name   │    department    │
├─────────┼──────────────────┤
│ Asha    │ Computer Science │
│ Farah   │ Computer Science │
│ Lakshmi │ Electronics      │
│ Meera   │ Computer Science │
│ Ravi    │ Electronics      │
└─────────┴──────────────────┘
┌────┬────────┬─────────┬───────────────────────────────────────────────────────────────────┐
│ id │ parent │ notused │                              detail                               │
├────┼────────┼─────────┼───────────────────────────────────────────────────────────────────┤
│ 6  │ 0      │ 45      │ SEARCH c USING COVERING INDEX sqlite_autoindex_courses_1 (code=?) │
│ 10 │ 0      │ 211     │ SCAN e USING COVERING INDEX sqlite_autoindex_enrolments_1         │
│ 15 │ 0      │ 45      │ SEARCH s USING INTEGER PRIMARY KEY (rowid=?)                      │
│ 18 │ 0      │ 45      │ SEARCH d USING INTEGER PRIMARY KEY (rowid=?)                      │
│ 26 │ 0      │ 0       │ USE TEMP B-TREE FOR ORDER BY                                      │
└────┴────────┴─────────┴───────────────────────────────────────────────────────────────────┘
┌────┬────────┬─────────┬───────────────────────────────────────────────────────────────────┐
│ id │ parent │ notused │                              detail                               │
├────┼────────┼─────────┼───────────────────────────────────────────────────────────────────┤
│ 6  │ 0      │ 45      │ SEARCH c USING COVERING INDEX sqlite_autoindex_courses_1 (code=?) │
│ 10 │ 0      │ 211     │ SCAN e USING COVERING INDEX sqlite_autoindex_enrolments_1         │
│ 15 │ 0      │ 45      │ SEARCH s USING INTEGER PRIMARY KEY (rowid=?)                      │
│ 18 │ 0      │ 45      │ SEARCH d USING INTEGER PRIMARY KEY (rowid=?)                      │
│ 26 │ 0      │ 0       │ USE TEMP B-TREE FOR ORDER BY                                      │
└────┴────────┴─────────┴───────────────────────────────────────────────────────────────────┘

Recorded with sql.js 1.14.2 (SQLite 3.49.1) on macOS 26 arm64. To run it yourself: sqlite3 -box :memory: < college.sql

The course-code SEARCH is the outer loop. SCAN e visits the enrolment key because it starts with student_id, while the course condition is on course_id. SEARCH s and SEARCH d use INTEGER PRIMARY KEY rowid lookups. The final temporary B-tree: A balanced search tree whose nodes are disk blocks of many sorted keys, each with its record. Every leaf is at the same depth, and every node but the root is at least half full. More in “B-trees and B+ trees: structure and order” sorts by student name; none of those facts follows merely from the written FROM order.

SQLite EXPLAIN shows an instruction listing rather than executing that query. Read setup, the dept_id test, ResultRow and the stopping branch below; this separate fixture defines an empty students table, so Rewind would take its empty-table branch to Halt:

The bytecode program of a query SQL · bytecode.sql
CREATE TABLE students (
  student_id INTEGER PRIMARY KEY,
  name       TEXT NOT NULL,
  dept_id    INTEGER NOT NULL,
  year       INTEGER NOT NULL
);

-- The program SQLite's bytecode engine would run for this query.
EXPLAIN SELECT name FROM students WHERE dept_id = 1;

Output

┌──────┬─────────────┬────┬────┬────┬──────────┬────┬─────────┐
│ addr │   opcode    │ p1 │ p2 │ p3 │    p4    │ p5 │ comment │
├──────┼─────────────┼────┼────┼────┼──────────┼────┼─────────┤
│ 0    │ Init        │ 0  │ 9  │ 0  │          │ 0  │         │
│ 1    │ OpenRead    │ 0  │ 2  │ 0  │ 3        │ 0  │         │
│ 2    │ Rewind      │ 0  │ 8  │ 0  │          │ 0  │         │
│ 3    │ Column      │ 0  │ 2  │ 1  │          │ 0  │         │
│ 4    │ Ne          │ 2  │ 7  │ 1  │ BINARY-8 │ 84 │         │
│ 5    │ Column      │ 0  │ 1  │ 3  │          │ 0  │         │
│ 6    │ ResultRow   │ 3  │ 1  │ 0  │          │ 0  │         │
│ 7    │ Next        │ 0  │ 3  │ 0  │          │ 1  │         │
│ 8    │ Halt        │ 0  │ 0  │ 0  │          │ 0  │         │
│ 9    │ Transaction │ 0  │ 0  │ 1  │ 0        │ 1  │         │
│ 10   │ Integer     │ 1  │ 2  │ 0  │          │ 0  │         │
│ 11   │ Goto        │ 0  │ 1  │ 0  │          │ 0  │         │
└──────┴─────────────┴────┴────┴────┴──────────┴────┴─────────┘

Recorded with sql.js 1.14.2 (SQLite 3.49.1) on macOS 26 arm64. To run it yourself: sqlite3 -box :memory: < bytecode.sql

An embedded database: A database engine linked into an application so its query operations run inside that application process. query is a function call in the application’s process, with no separate database server. A client-server database: A database arrangement in which client applications connect to separate server processes that manage shared data and authorisations. instead connects to server processes that manage roles and concurrent work. A database worker model is separate from application tiers: a client, application server and database make three tiers.

Ask the engine its version when the environment changes, since bundled browser and Python libraries can differ. Plans and opcode listings belong to the build that produced them. Plain EXPLAIN gives estimates; EXPLAIN ANALYZE runs the query and adds actual evidence, so compare estimated and actual rows before treating a slow run as only an application problem.

Checkpoint

Check: Cooperating query stages · Row access and working pages

  1. Question 1 of 3 Which boundary asks for pages rather than returning application rows?

    Choose one answer.

    Show the answer: Question 1 of 3

    Answer: Buffer manager

    Rows and pages belong to cooperating but different stages.

  2. Question 2 of 3 The FROM order changes but the complete plan is identical. Who chose the loop order?

    Choose one answer.

    Show the answer: Question 2 of 3

    Answer: The planner

    The college evidence separates the written table order from the chosen nested loops.

  3. Question 3 of 3 A required page is already in the buffer manager. Does that page need a new disk read for this request?

    Choose one answer.

    Show the answer: Question 3 of 3

    Answer: No

    A warm page can make the same access path cheaper to execute without a schema or SQL change.

Prepare SQL and read the full college join plan Pro: opens with a Pro, Premium or Ultimate pass

The complete college case separates grammar, name resolution and row validity, then reads every nested loop and its final sort. The same data and both original plan outputs remain available in the worked example above.

In this part:

  • How the full pipeline connects its stages
  • Preparing SQL checks text, names and view definitions
  • The planner chooses access paths and loop order

3 diagrams · 1 runnable example (SQL) · about 11 minutes

Opening this part with your pass…

This part opens with any MySmartCoPilot pass.

  • Pro pass · 1 week₹79$2.99
  • 30 days₹179$5.99
  • 1 year₹1,699$45

One payment; nothing renews unless you choose to. The price shown is the total you pay: no fees or charges are added at checkout.

It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

Read bytecode, pages and transaction protection Pro: opens with a Pro, Premium or Ultimate pass

The instruction listing, storage readout and transaction services describe different layers of the same engine. Keep every conditional branch and page value distinct from an observed populated-table execution.

In this part:

  • The bytecode listing separates setup, rows and stopping
  • Row access and working pages keep key lookups and ordering distinct
  • Locks and logs protect the work around the executor

3 diagrams · 1 runnable example (SQL) · about 9 minutes

Opening this part with your pass…

This part opens with any MySmartCoPilot pass.

  • Pro pass · 1 week₹79$2.99
  • 30 days₹179$5.99
  • 1 year₹1,699$45

One payment; nothing renews unless you choose to. The price shown is the total you pay: no fees or charges are added at checkout.

It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

Choose placement and interpret costs and versions Pro: opens with a Pro, Premium or Ultimate pass

The original comparisons place SQLite and PostgreSQL differently while retaining their full process and application-tier descriptions. The scan estimate and genuine version queries supply the concrete values needed to read those choices.

In this part:

  • Embedded and server engines place the same jobs differently
  • Worker models and application tiers answer different questions
  • A PostgreSQL plan prices work and reports rows
  • The version comes from the engine that actually runs
  • What the complete engine paths establish

4 diagrams · 2 runnable examples (Python, SQL) · about 12 minutes

Opening this part with your pass…

This part opens with any MySmartCoPilot pass.

  • Pro pass · 1 week₹79$2.99
  • 30 days₹179$5.99
  • 1 year₹1,699$45

One payment; nothing renews unless you choose to. The price shown is the total you pay: no fees or charges are added at checkout.

It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

Practise

Exercise · Easy · SQL

Fix a query that fails at three stages

The query in the editor should list the students enrolled in the course with the code CS302, with the course's title, in two columns: name and title. It has three mistakes, and SQLite reports only one at a time: each fix lets the query get one stage further before the next error stops it.

Run the sample tests, read the error, fix that mistake, and run them again until the query returns the right rows. The tests create these tables (with different rows in each test):

  • students (student_id INTEGER PRIMARY KEY, name TEXT NOT NULL)
  • courses (course_id INTEGER PRIMARY KEY, code TEXT NOT NULL UNIQUE, title TEXT NOT NULL)
  • enrolments (student_id INTEGER NOT NULL, course_id INTEGER NOT NULL, PRIMARY KEY (student_id, course_id))

The order of the rows does not matter.

Starter code · query.sql

-- The students enrolled in CS302, with the course title. Fix the three mistakes.
SELEC s.name, c.title
FROM enrolment AS e
JOIN students AS s ON s.student_id = e.student_id
JOIN courses AS c ON c.course_id = e.course_id
WHERE c.code = CS302;
The sample tests · sample_tests.yaml
# Sample tests (public): each test builds the three tables in a fresh database, runs the learner's query and compares
# the result with the expected rows (the order of rows does not matter; column names must match).
tests:
  - name: lists the two students enrolled in CS302
    setup: |
      CREATE TABLE students (student_id INTEGER PRIMARY KEY, name TEXT NOT NULL);
      CREATE TABLE courses (course_id INTEGER PRIMARY KEY, code TEXT NOT NULL UNIQUE, title TEXT NOT NULL);
      CREATE TABLE enrolments (student_id INTEGER NOT NULL, course_id INTEGER NOT NULL, PRIMARY KEY (student_id, course_id));
      INSERT INTO students VALUES (1, 'Asha'), (2, 'Ravi'), (3, 'Meera'), (8, 'Arjun');
      INSERT INTO courses VALUES (1, 'CS301', 'Database Systems'), (2, 'CS302', 'Operating Systems');
      INSERT INTO enrolments VALUES (1, 1), (1, 2), (2, 1), (3, 1), (8, 2);
    expected:
      columns: [name, title]
      rows:
        - [Asha, Operating Systems]
        - [Arjun, Operating Systems]
  - name: returns only CS302 when several courses share students
    setup: |
      CREATE TABLE students (student_id INTEGER PRIMARY KEY, name TEXT NOT NULL);
      CREATE TABLE courses (course_id INTEGER PRIMARY KEY, code TEXT NOT NULL UNIQUE, title TEXT NOT NULL);
      CREATE TABLE enrolments (student_id INTEGER NOT NULL, course_id INTEGER NOT NULL, PRIMARY KEY (student_id, course_id));
      INSERT INTO students VALUES (4, 'Kiran'), (5, 'Farah'), (6, 'Joseph'), (7, 'Lakshmi');
      INSERT INTO courses VALUES (10, 'CS302', 'Operating Systems'), (11, 'MA201', 'Probability'), (12, 'CS303', 'Compilers');
      INSERT INTO enrolments VALUES (4, 10), (4, 11), (5, 12), (6, 10), (7, 11), (7, 12);
    expected:
      columns: [name, title]
      rows:
        - [Kiran, Operating Systems]
        - [Joseph, Operating Systems]
A hint

Read the first error only. "Syntax error" comes from the parser and points at a word the grammar does not know; once that is fixed, "no such table" and "no such column" come from checking names against the catalog. A word that is meant as text needs single quotes.

The sample tests run on this device, in your browser (sql.js): nothing is sent to mysmartcopilot.com. The first run downloads SQLite (about 0.7 MB), which is kept for the next runs. A check in your browser is feedback for you, not proof that the code is right for every input.

Practice that adapts to you

Practise this lesson

20 questions about 10 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.

  1. Question 1 of 20 Put the parts of the engine in the order a query reaches them, from the SQL text down to the disk.

    Give each item its position, from 1 (first).

    Show the answer: Question 1 of 20

    Answer:

    1. Parser
    2. Rewriter
    3. Planner
    4. Executor
    5. Access methods
    6. Buffer manager
    7. Storage

    The text is parsed and its names checked, views are rewritten into their tables, the planner chooses how to run the query, and the executor runs the plan. The executor asks the access methods for rows, they ask the buffer manager for pages, and only pages that are not in memory are read from storage.

  2. Question 2 of 20 In the plan of the college query, SQLite implements the joins as nested loops. Which table does the outer loop read?

    Choose one answer.

    Show the answer: Question 2 of 20

    Answer: courses (c), through the index on code

    The lines of an EXPLAIN QUERY PLAN are the loops from outermost to innermost, and the first line is SEARCH c USING COVERING INDEX sqlite_autoindex_courses_1 (code=?). The WHERE clause on code narrows courses to one row, so starting there keeps every inner loop small.

  3. Question 3 of 20 Which line of the college plan reads every entry of something, and why?

    Choose one answer.

    Show the answer: Question 3 of 20

    Answer: SCAN e, because the primary-key index of enrolments starts with student_id, not course_id

    SCAN means a full pass, here over the index sqlite_autoindex_enrolments_1. That index is ordered by student_id first, so SQLite cannot jump to the entries of one course. With fourteen enrolments it costs nothing; with millions, an index that starts with course_id would turn the line into a SEARCH.

  4. Question 4 of 20 What does "SEARCH s USING INTEGER PRIMARY KEY (rowid=?)" tell you?

    Choose one answer.

    Show the answer: Question 4 of 20

    Answer: Each student is found with one lookup by key in the table's own B-tree

    student_id is an INTEGER PRIMARY KEY, which in SQLite is the rowid, the key of the table's B-tree. For every enrolment, SQLite searches that B-tree for one row instead of scanning the table.

  5. Question 5 of 20 Why does the plan end with "USE TEMP B-TREE FOR ORDER BY"?

    Choose one answer.

    Show the answer: Question 5 of 20

    Answer: The rows come out in enrolment order, so SQLite sorts them by name before returning them

    No index delivers the rows ordered by s.name, so SQLite collects them into a temporary B-tree sorted by name and returns them from there. An index that gave the rows already in name order would remove this step.

  6. Question 6 of 20 A PostgreSQL server receives a new client connection. What does it start for it?

    Choose one answer.

    Show the answer: Question 6 of 20

    Answer: A new backend process, started by the postmaster, which serves that connection

    PostgreSQL's manual describes a process per user model: the postmaster listens for connections and starts a backend process for each one, and the backends share data through shared memory. MySQL, by contrast, gives each connection a thread.

  7. Question 7 of 20 The required page is absent from memory. Which stage supplies it to the buffer manager?

    Choose one answer.

    Show the answer: Question 7 of 20

    Answer: Storage

    The cooperating path reaches storage only when the needed page is not already available in memory.

  8. Question 8 of 20 What does SQLite EXPLAIN return for the one-table query?

    Choose one answer.

    Show the answer: Question 8 of 20

    Answer: An instruction listing instead of executing that query

    The free example displays the complete listing and distinguishes that description from a real query execution.

  9. Question 9 of 20 The displayed bytecode fixture defines no student rows. What does the Rewind empty-table branch do?

    Choose one answer.

    Show the answer: Question 9 of 20

    Answer: Jump to Halt

    Read the empty branch of this fixture separately from the different populated college database.

  10. Question 10 of 20 Which services coordinate concurrent work and its recovery information?

    Choose one answer.

    Show the answer: Question 10 of 20

    Answer: Locks or concurrency control, and the log or journal

    These services surround the execution and access path rather than replacing the SQL result computation.

  11. Question 11 of 20 A caller still splits a read, arithmetic and write into unsafe operations. Is moving the file into a DBMS alone sufficient?

    Choose one answer.

    Show the answer: Question 11 of 20

    Answer: No

    The engine provides mechanisms; the application must use a safe request boundary.

  12. Question 12 of 20 How does the SQLite query arrive in the original embedded comparison?

    Choose one answer.

    Show the answer: Question 12 of 20

    Answer: A library call inside the application process

    The process placement differs from a server that accepts SQL over connections.

  13. Question 13 of 20 Many programs and people need a shared database over connections. Which original deployment shape matches that requirement?

    Choose one answer.

    Show the answer: Question 13 of 20

    Answer: Client-server

    The original comparison associates an embedded engine with an application or device and a server with connected shared-data users.

  14. Question 14 of 20 A client talks to an application server, which alone talks to the database. How many application tiers are described?

    Choose one answer.

    Show the answer: Question 14 of 20

    Answer: Three

    Keep the original process model and tier vocabulary distinct.

  15. Question 15 of 20 Which PostgreSQL command actually runs the query while describing its plan?

    Choose one answer.

    Show the answer: Question 15 of 20

    Answer: EXPLAIN ANALYZE

    The free core names the difference so a reader does not mistake estimates for an observed execution.

  16. Question 16 of 20 A plan's estimated rows differ greatly from its observed rows. Which input to the planner should be checked?

    Choose one answer.

    Show the answer: Question 16 of 20

    Answer: Its statistics

    Read estimates against actual execution rather than assuming the chosen estimate describes today's data.

  17. Question 17 of 20 What is the dependable way to identify the SQLite build used by a new lab?

    Choose one answer.

    Show the answer: Question 17 of 20

    Answer: Ask that running engine for its version

    A package can carry the library it was built or linked with; identify the actual environment.

  18. Question 18 of 20 The browser and Python measurements return different SQLite versions. What follows for reading an EXPLAIN listing?

    Choose one answer.

    Show the answer: Question 18 of 20

    Answer: Use the version that produced that listing

    Different genuine measurements are meaningful; they are not repaired by hardcoded output or a rebound record.

  19. Question 19 of 20 For the two cases, select each correct answer. Case A: Which category includes a missing table name in otherwise valid SQL? Case B: What does a view store for the engine to process?

    Choose every answer that is right.

    Show the answer: Question 19 of 20

    Answer:

    • Case A: Name resolution during preparation
    • Case B: A defining query

    Case A: Separate the grammar of the text, the catalog names and the data rules instead of treating every error as the same stage. Case B: A view presents a reading interface through its definition, which reaches the planner through the engine's compilation or rewriting path.

  20. Question 20 of 20 For the two cases, select each correct answer. Case A: A valid insert uses year 5 for a column limited to years 1 through 4. Where does it fail? Case B: Why can a query written through a view still involve indexes on its underlying tables?

    Choose every answer that is right.

    Show the answer: Question 20 of 20

    Answer:

    • Case B: The engine processes the defining query
    • Case A: Execution of the row constraint

    Case A: The college schema publicly states the year range; preparation does not make an out-of-range row acceptable. Case B: The free path explains a view reference as input to the same planning work; the exact engine mechanism is developed in the depth section.

Interview questions

Fresher · What happens to a SQL query between the moment it is sent and the first row coming back?

The engine parses the text into a tree and checks the table and column names against its catalog. It rewrites the tree, replacing views with their underlying tables. The planner then considers different ways to run the query, such as a full scan or an index, and different join orders, estimates their costs from statistics and picks the cheapest. The executor runs that plan: it asks the access methods for rows of tables and indexes, which get pages from the buffer manager, which reads from disk only the pages that are not already in memory. Locks and the log keep concurrent transactions correct and changes durable. In PostgreSQL this happens in a server process per connection; in SQLite it happens inside the application, and the plan becomes bytecode for SQLite’s virtual machine.

Fresher · What is the difference between an embedded database engine and a client-server engine?

An embedded engine such as SQLite is a library inside the application: queries are function calls, there is no server or network, the database is an ordinary file, and access is controlled by the operating system’s file permissions. SQLite allows one writer at a time per file. A client-server engine such as PostgreSQL runs as server processes of its own; applications connect over a network and send SQL text, and the server manages users, privileges and many concurrent writers. PostgreSQL starts a process for each connection, while MySQL uses a thread per connection. Embedded engines suit data that belongs to one application or device; client-server engines suit data that many programs and people share.

  1. Mid to senior

    A report query took 40 ms yesterday and takes 9 seconds today. Nobody changed its text or the schema. Using the stages a query goes through, where do you look first, and in what order?

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page. First step and follow-ups

  2. Fresher to mid

    A web app runs 40 worker processes on two servers, all writing to one SQLite file on a network share. Users see "database is locked" errors and, twice this month, a corrupted database. Explain both problems and what you would change.

    Model answer, Pro. First step and follow-ups

  3. Mid to senior

    The college report filters on course code, but its enrolment key starts with student_id and the plan scans enrolments. The table grows from 14 to two million rows. Why does reordering FROM not solve it, and what change would you assess?

    Model answer, Pro. First step and follow-ups

Key takeaways

  • A query has grammar, name, planning and execution stages; identify the stage before changing its text or data.
  • The query plan: The access operations and their order that a database engine chooses to produce a query result. supplies the access order, while page residency can change the storage work needed to execute it.
  • Read the version and distinguish a displayed plan or instruction listing from the query execution that EXPLAIN ANALYZE performs.

Terms in this lesson

buffer manager
The engine component that keeps database pages in memory and supplies a held page or fetches a missing one from storage.
client-server database
A database arrangement in which client applications connect to separate server processes that manage shared data and authorisations.
database access method
An engine operation for reading or changing table or index rows through their storage structure.
database bytecode
An instruction program prepared by an engine such as SQLite to implement a statement through its bytecode virtual machine.
embedded database
A database engine linked into an application so its query operations run inside that application process.
query executor
The engine component that follows the chosen plan to produce rows, using the underlying access methods.
query parser
The part of an engine that recognises the grammar of a SQL statement and forms a representation for later preparation.
query plan
The access operations and their order that a database engine chooses to produce a query result.
query planner
The engine component that chooses access paths and operation order using estimates of the work needed to produce the requested result.

Corrections

  • Clarified that the recorded SQLite version on macOS identifies the linked library; its supplier is not established by the version query.
  • Clarified that newly prepared SQL follows compilation stages; a reusable prepared statement can retain compiled work for later execution.

References

Related tools

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.