Lecture 01: Why Databases?
File Systems vs DBMS, 3-Schema Architecture, Data Independence, and Schemas vs Instances
Lecture Source Slide Deck
Original Slides: Lecture 01 (138 slides) · Amit Kumar Dhar (IIT Bhilai)
Download lecture01.pdf
1. Motivation: Why Not Just Use Plain Files?
Before DBMS, systems stored persistent records in flat OS files (e.g., CSV, text, or binary files) managed by application code. This file-processing approach suffers from severe fundamental shortcomings:
- Data Redundancy and Inconsistency:
- Different programs create their own copies of files, leading to duplicated data across departments.
- When updates occur in one file but not another, data becomes contradictory.
- Difficulty in Accessing Data:
- Answering an ad-hoc query (e.g., "Find all students with GPA > 8.5 in CSE") requires writing a new dedicated C or Python script.
- Data Isolation:
- Data is scattered in various files with different formats, making joins or cross-referencing extraordinarily tedious.
- Integrity Problems:
- Constraints (e.g.,
balance >= 0orcredits in (3, 4)) are hard-coded in application logic. When constraints change, every application modifying the files must be audited and rewritten.
- Constraints (e.g.,
- Atomicity Problems:
- In a banking transfer from Account A to Account B, if the machine crashes after debiting A but before crediting B, money vanishes. File systems lack transaction boundaries.
- Concurrent-Access Anomalies:
- Multiple programs updating the same file simultaneously cause lost updates and corrupted files without fine-grained locking.
- Security Problems:
- File systems enforce permissions only at the OS file level; they cannot selectively restrict access to specific rows or columns.
2. The Three-Schema Architecture (ANSI/SPARC)
To decouple user applications from the physical storage details, the ANSI/SPARC architecture defines three distinct levels of abstraction:
+-------------------------------------------------------------+
| External Level (Views / Subschemas for Users & Apps) |
| [Student Portal View] [Registrar Transcript View] |
+-------------------------------------------------------------+
|
Logical Data Independence
|
+-------------------------------------------------------------+
| Conceptual Level (Logical Schema: Entities & Relations) |
| student, course, instructor, takes |
+-------------------------------------------------------------+
|
Physical Data Independence
|
+-------------------------------------------------------------+
| Internal Level (Physical Storage, Indexes, B-Trees) |
| Disk layout, page blocks, secondary indexes |
+-------------------------------------------------------------+The Three Levels Explained
- External Level (View Schema):
- Describes the part of the database relevant to a specific user group.
- Hides irrelevant or sensitive data (e.g., a student view cannot see instructors' salaries).
- Conceptual Level (Logical Schema):
- Describes what data is stored in the database and the relationships among data items for the entire organization.
- Independent of storage hardware or specific file structures.
- Internal Level (Physical Schema):
- Describes how data is actually stored physically on storage media (record layouts, B+ tree indexes, hashing, block sizes, compression).
3. Data Independence
Data independence is the capacity to change the schema at one level without having to alter the schema at the next higher level.
Physical Data Independence
- The capacity to modify the internal physical schema without requiring changes to the conceptual (logical) schema.
- Example: Creating a new B-Tree index on
student(dept_name)or moving tables across SSDs does not require rewriting application SQL queries or altering table schemas.
Logical Data Independence
- The capacity to modify the conceptual schema without altering existing external schemas or application programs.
- Example: Adding a new attribute
student(phone_number)or adding a new tableextracurriculardoes not break applications that only querystudent(id, name). - Note: Logical data independence is significantly harder to achieve than physical data independence because application logic is inherently tied to conceptual entities.
4. Schema vs. Instance
| Concept | Definition | Analogy | Time Sensitivity |
|---|---|---|---|
| Schema (Intension) | The overall structural design and description of the database (table definitions, attribute types, constraints). | Variable declaration / Type definition in code | Changes very rarely. |
| Instance (Extension) | The actual collection of data stored in the database at a specific snapshot in time. | The value assigned to a variable during execution | Changes constantly as data is inserted, updated, or deleted. |
5. Review Exercises & Conceptual Questions
Answer:
A file-processing system relies on coarse OS file locks, which either lock the entire file or leave concurrent edits uncoordinated. A DBMS implements concurrency control subsystems (such as Two-Phase Locking [2PL] or Multi-Version Concurrency Control [MVCC]) that acquire granular row- or page-level locks, ensuring transactions satisfy the Isolation property of ACID and serializing updates without data loss.
Answer:
Physical data independence only alters internal representations (e.g., switching from heap files to B+ trees), which the query compiler abstracts away transparently. In contrast, changes to the logical schema (e.g., splitting a table, changing foreign key relationships) frequently affect the entities and attributes queried by application programs, requiring the creation and maintenance of backward-compatible views.
Answer:
- DDL Compiler: Translates schema definition statements (
CREATE,ALTER,DROP) into a set of tables stored in the data dictionary (system catalog / metadata). - DML Compiler / Query Optimizer: Translates declarative data manipulation statements (
SELECT,INSERT,UPDATE,DELETE) into an optimized physical execution plan composed of relational operators.