Quiz 2
Registry Synced

02 - DBMS Architecture

1730 words
9 min read

Reading compass

Now · 🎯 Learning Objectives

02 - DBMS Architecture

🎯 Learning Objectives

After reading this topic, you will be able to:
  • Diagram the major components of a DBMS (storage manager, query processor, transaction manager)
  • Describe how a query flows from submission to result
  • Explain the role of the storage manager, buffer manager, and file manager
  • Differentiate between centralized, client-server, parallel, and distributed architectures
  • List database system internals (parsing, optimization, evaluation)

📋 Prerequisites

📖 Core Content

2.1 Intuition: What Happens When You Run a Query?

When you type SELECT name FROM instructor WHERE salary > 80000; and press Enter, what happens? You see results in milliseconds. But behind the scenes, the DBMS goes through an elaborate pipeline: (Diagram)
  1. Parsing & Translation: SQL is parsed, validated (table/column existence), and translated to relational algebra
  2. Optimization: The optimizer considers multiple evaluation plans and chooses the cheapest (by I/O cost, CPU, etc.)
  3. Execution: The executor runs the chosen plan, calling the storage manager to read/write data
  4. Result: Results are formatted and returned to the user
Why This Matters: Understanding this pipeline helps you write efficient queries. A poorly written query can be 1000× slower than a good one — even if they return the same results!

2.2 The Query Processor

The query processor has three components:

Parsing and Translation

  • Checks SQL syntax
  • Validates that tables and columns exist
  • Translates SQL into relational algebra (internal representation)
  • Relational algebra is procedural — it tells the system how to execute

Optimization

The optimizer considers equivalent expressions (different relational algebra trees) and chooses the cheapest:
sql
SELECT name
FROM instructor, teaches
WHERE instructor.ID = teaches.ID AND teaches.year = 2018;
This could be executed as:
  • Cartesian product → σ (year=2018) → σ (ID match) → π name
  • σ (year=2018) on teaches → ⋈ on ID → π name
  • Many other plans The optimizer estimates costs using:
  • Number of I/O operations (dominant factor)
  • CPU processing time
  • Network communication (for distributed systems)
Key insight: The cost difference between a good plan and a bad plan can be enormous (seconds vs. hours).

Evaluation

The executor runs the chosen plan step by step:
  • Performs selections, projections, joins
  • May involve sorting, grouping, aggregation
  • Returns result tuples to the user

2.3 The Storage Manager

The storage manager is the bridge between the query processor and the physical data. It consists of: (Diagram)
ComponentRole
File ManagerAllocates/deallocates disk blocks; manages file structure
Buffer ManagerBrings data between disk and main memory (caching)
Index ManagerCreates and maintains indices for fast access

Buffer Manager

The buffer manager divides main memory into pages. When data is requested:
  1. Check if the page is already in the buffer (cache hit)
  2. If not, read from disk (cache miss)
  3. If buffer is full, evict a page using a policy (LRU, Clock, etc.) Buffer management is critical because disk I/O is the dominant cost in database operations.

2.4 Transaction Management

A transaction is a collection of operations that performs a single logical function. Example: Transfer $500 from account A to account B
pseudo
1. Read A          -- balance_A = 1000
2. Write A - 500   -- balance_A = 500
3. Read B          -- balance_B = 200
4. Write B + 500   -- balance_B = 700
5. Commit

The Transaction Manager ensures ACID properties:

PropertyWhat It MeansHow It's Achieved
AtomicityAll or nothing — either all operations complete or none doLog-based recovery (undo/redo)
ConsistencyDatabase remains in a valid state before and afterIntegrity constraints, application code
IsolationConcurrent transactions don't interfere with each otherConcurrency control (locking, timestamping)
DurabilityCommitted changes persist even after failuresLog-based recovery (redo)
Without transaction management:
  • Atomicity: Crash after step 2 but before step 4 → $500 disappears (inconsistent)
  • Isolation: Two transfers from same account simultaneously → both read 1000,bothwrite1000, both write500 → $1000 lost!

The Concurrency-Control Manager

Coordinates simultaneous access. Uses:
  • Locking protocols (shared/exclusive locks, two-phase locking)
  • Timestamp ordering (older transactions get priority)
  • Optimistic methods (validate at commit time)

2.5 Database Architecture Types

(Diagram)
ArchitectureDescriptionUse Case
CentralizedSingle machine, single databaseSmall organizations, personal DB
Client-ServerMultiple clients connect to one DB serverMost web applications
ParallelMultiple CPUs sharing disk for throughputData warehousing, analytics
DistributedMultiple databases at different sites connected via networkGlobal enterprises, fault tolerance
Cloud DBDatabase as a service (AWS RDS, Google Cloud SQL)Modern web apps, scalability

2.6 Database System Internals: The Big Picture

(Diagram)

2.7 Database Administrators and Users

RoleResponsibilities
Database Administrator (DBA)Schema definition, storage structure, security, backup, performance tuning
Application ProgrammerWrites application code that queries the database
Sophisticated UserWrites complex queries directly (analysts, data scientists)
Naive UserUses application interfaces (ATMs, web forms)
The DBA uses administrative tools to:
  • Create and modify schemas
  • Grant/revoke permissions
  • Monitor performance
  • Schedule backups
  • Handle crash recovery

📐 Key Formulas / Concepts

ComponentFunction
ParserValidates SQL syntax and translates to relational algebra
OptimizerSelects cheapest execution plan from equivalent alternatives
ExecutorRuns the chosen plan and returns results
Storage ManagerManages disk storage, buffering, and indexing
Transaction ManagerEnsures ACID properties
Concurrency ControlManages simultaneous access to shared data
Recovery ManagerRestores database to consistent state after failures

⚠️ Common Pitfalls

Pitfall 1: Thinking Query Optimization is Magic

The Mistake: "I don't need to worry about query performance — the optimizer fixes everything." Why It's Wrong: Optimizers are good, but they can't fix fundamentally bad queries. A Cartesian product of million-row tables followed by a WHERE clause is always expensive. The optimizer can choose join order, but it can't invent missing indexes. Correct: Write queries efficiently, create appropriate indexes, and understand your data distribution.

Pitfall 2: Confusing Centralized and Client-Server

The Mistake: "My laptop runs PostgreSQL, so it's client-server." Why It's Wrong: Client-server means separate machines for client and server. If both are on the same machine, it's still a client-server architecture, but physically it's centralized. The distinction is about the architecture pattern, not the hardware. Correct: Client-server is defined by the separation of concerns — the client handles the user interface, the server handles data management. They may or may not be on the same machine.

Pitfall 3: Underestimating Buffer Manager Impact

The Mistake: "Disk is slow, but my query only needs one table." Why It's Wrong: Even a simple query may need to read thousands of blocks. Without good buffer management (caching), every block access is a disk I/O. With good caching, frequently used blocks stay in memory. Correct: The buffer manager's cache hit ratio is one of the most important performance metrics for a database.

📝 Practice Questions

Q1. What are the three components of a query processor? Briefly explain each.

Answer
  1. Parser & Translator: Checks SQL syntax, validates table/column names, and translates SQL to relational algebra (internal representation)
  2. Optimizer: Generates multiple execution plans and picks the cheapest based on cost estimates (I/O operations, CPU, network)
  3. Executor: Runs the chosen plan step-by-step, coordinating with the storage manager to read/write data

Q2. List the ACID properties and what each ensures.

Answer
  • Atomicity: Transaction completes fully or not at all (all-or-nothing)
  • Consistency: Transaction brings database from one valid state to another
  • Isolation: Concurrent transactions appear to run serially (no interference)
  • Durability: Committed changes persist even after system failures

Q3. What does the buffer manager do? Why is it important?

Answer
The buffer manager manages data movement between disk and main memory. It:
  • Checks if requested data is already in memory (cache hit)
  • Loads data from disk if not in memory (cache miss)
  • Evicts pages when memory is full using policies like LRU
It's important because disk I/O is the dominant cost in database operations. Effective buffering (high cache hit rate) can make queries 10-100× faster.

Q4. Compare centralized and distributed database architectures.

Answer
AspectCentralizedDistributed
LocationSingle machineMultiple sites
Data storageSingle databaseMultiple databases
ProsSimple management, consistentFault tolerance, scalability, local autonomy
ConsSingle point of failure, limited scalabilityComplex management, network overhead, consistency challenges
ExampleSmall business systemGlobal banking system

Q5. Why is the cost of a bad query plan potentially enormous?

Answer
A naive plan might:
  • Read every block of every table (full table scans)
  • Compute Cartesian products before filtering
  • Not use available indexes
For a 10-million-row table, this could mean reading gigabytes of data from disk, taking minutes or hours. A good plan with index usage and optimal join order might take milliseconds.

Q6. What is the role of the concurrency-control manager?

Answer
The concurrency-control manager ensures isolation by coordinating simultaneous access to data. It:
  • Manages locks on data items (shared/exclusive)
  • Ensures serializability (concurrent execution produces same result as some serial execution)
  • Detects and resolves deadlocks
  • Uses protocols like two-phase locking, timestamp ordering, or optimistic concurrency control
Without it, concurrent transactions could interfere (lost updates, dirty reads, incorrect summaries).

Q7. List three tasks performed by a Database Administrator.

Answer
  1. Schema definition: Creating and modifying database schemas
  2. Security management: Granting/revoking user privileges
  3. Backup and recovery: Scheduling backups, handling crash recovery
Other valid answers: Performance monitoring, storage management, user account management.

Q8. A bank transfer transaction debits ₹500 from account A and credits ₹500 to account B. After the debit but before the credit, the system crashes. What does the recovery manager do?

Answer
The recovery manager checks the transaction log:
  • It finds a <T_start> record
  • It finds a <T, A, old_value, new_value> for the debit
  • It does NOT find a <T_commit> or <T_abort> record
Since the transaction didn't complete, the recovery manager performs an undo: it restores account A's balance to its original value (before the debit). This ensures atomicity — the incomplete transaction is fully rolled back.

🔗 Cross-References

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.