DBMS Study Notes Part2
DBMS Study Notes Part2
· Indexes
DATABASE MANAGEMENT
SYSTEMS
Comprehensive Study Notes — Part II
3NF vs BCNF | Decomposition | Multiple Granularity | Serializability | Validation Protocol | File
Organization | Indexes
In simple words, 3NF allows a non-key attribute to determine another non-key attribute, as long
as the dependent attribute is part of a candidate key. This is the exception 3NF makes.
Page 1 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
Functional dependencies:
• (StudentID, CourseID) → InstructorID [composite key determines instructor]
• InstructorID → InstructorPhone [instructor determines phone]
BCNF is stricter than 3NF. It removes every case where a non-superkey attribute determines
another attribute, even if the dependent attribute is prime.
Functional dependencies:
• (Student, Course) → Instructor
• Instructor → Course
The dependency Instructor → Course violates BCNF because Instructor alone is not a superkey
(it cannot uniquely identify a row). However, this table is in 3NF because Course is a prime
attribute (part of the candidate key (Student, Course)).
Page 2 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
This is the main reason 3NF is sometimes preferred over BCNF in practice — 3NF guarantees
that all functional dependencies are preserved after decomposition, while BCNF does not.
Summary:
3NF makes one exception: it allows non-superkey determinants if the result is a prime
attribute. BCNF makes no exceptions — every determinant must be a superkey. BCNF is
stronger but may sacrifice dependency preservation.
Page 3 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
2. Properties of Decompositions
Decomposition is the process of breaking a large table (relation) into two or more smaller tables
to remove redundancy and fix anomalies. However, not every decomposition is good. A good
decomposition must satisfy certain important properties.
A decomposition is lossy if the join produces extra rows that were not in the original table. This
is dangerous because it creates incorrect query results.
Page 4 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
If a dependency is split across two tables, it cannot be enforced directly. Every time we insert or
update data, we would need to join the tables to verify the constraint, which is slow and error-
prone.
Now consider decomposing into R1(A, B) and R2(A, C). The dependency B → C is split —
neither R1 nor R2 contains both B and C together. This decomposition does NOT preserve B →
C.
Property 3: No Redundancy
The decomposed tables should not contain repeated data. Each fact should be stored in exactly
one place. If the same data appears in multiple tables after decomposition, updates will require
changing multiple tables, leading to inconsistency.
A good decomposition ensures each sub-table is in a higher normal form (3NF or BCNF), which
naturally reduces redundancy.
Summary of Properties
Property What It Means Why It Matters
Lossless Join Original table can be Prevents false rows and data
reconstructed by joining sub- corruption
tables
Dependency Preservation All FDs can be checked Ensures constraints can be
within a single sub-table enforced easily
No Redundancy Each fact stored only once Prevents update and deletion
Page 5 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
Key Fact:
Both lossless join and dependency preservation are always achievable with 3NF
decomposition. BCNF decomposition always gives lossless join but may lose dependency
preservation.
Page 6 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
3. Multiple Granularity
In a database, locking is used to prevent two transactions from conflicting with each other. But
not all locks need to be on individual rows. Sometimes it is more efficient to lock a large group of
data (like a whole table) all at once. This concept is called Multiple Granularity Locking.
Definition
Multiple Granularity refers to a locking scheme where data can be locked at different levels of
size (granularity) — from a single row at the finest level, up to the entire database at the
coarsest level. The word 'granularity' means the size of the unit being locked.
Granularity Hierarchy
The database is organized in a tree-like hierarchy:
DATABASE
|
TABLE (Relation)
|
PAGE (Disk Block)
|
ROW (Tuple / Record)
• Database: Locking the entire database. No other transaction can access anything.
• Table: Locking a whole table. All rows in that table are locked.
• Page: Locking a disk block (a group of rows stored together on disk).
• Row (Tuple): Locking a single record. The finest level of locking.
On the other hand, a transaction that only needs to update 3 specific rows should not lock the
whole table — that would block all other transactions unnecessarily. It should lock only those 3
rows.
Multiple Granularity gives the flexibility to choose the right level of locking based on what the
transaction needs.
Page 7 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
Page 8 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
X ✗ ✗ ✗ ✗ ✗
Key Point:
Intention locks are placed top-down (from database to row) before the actual lock. Locks
are released bottom-up (from row back to database). This protocol ensures no two
conflicting locks exist anywhere in the hierarchy.
Page 9 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
4. Serializability
When many transactions run at the same time (concurrently), their operations get mixed
together. The final result of this mixed execution must be correct — meaning it should be as if
the transactions ran one after another, not mixed. This idea is called Serializability.
Definition
A schedule is a sequence of operations (reads and writes) from multiple transactions. A
schedule is said to be serializable if its result is equal to the result of some serial execution of
the same transactions. A serial execution means transactions run completely one after another
with no overlapping.
A serial schedule is always correct but slow — all other transactions wait. A concurrent
schedule is faster, but may give wrong results if not managed properly.
Types of Serializability
1. Conflict Serializability
Two operations conflict if they are from different transactions, operate on the same data item,
and at least one is a write.
• Read-Write conflict: One reads while another writes the same item
• Write-Read conflict: One writes while another reads the same item
• Write-Write conflict: Both write to the same item
Page 10 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
2. View Serializability
A schedule is view serializable if it is view equivalent to some serial schedule. View equivalence
has three conditions:
10. Initial reads: If Ti reads initial value of A in the serial schedule, Ti must read initial value
of A in the concurrent schedule too.
11. Updated reads: If Ti reads a value written by Tj in one schedule, the same must happen
in the other.
12. Final writes: The last write to every data item must be done by the same transaction in
both schedules.
Every conflict serializable schedule is also view serializable, but not the other way around. View
serializability is harder to test (NP-complete problem), so conflict serializability is used in
practice.
Key Point:
All serial schedules are serializable. The goal of concurrency control is to allow concurrent
execution while guaranteeing the result equals some serial execution.
Page 11 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
Why Optimistic?
Lock-based methods are pessimistic — they assume conflicts will happen and block
transactions in advance. Validation-based methods are optimistic — they assume conflicts are
unlikely, let transactions run without restrictions, and only validate at the end. If no conflict is
found, the transaction commits. If a conflict is found, the transaction is rolled back and restarted.
Transaction T:
Read: A = 1000 (from actual DB, store locally)
Compute: A = A - 200 = 800
Write: A = 800 (stored only in local/temp copy, NOT in DB yet)
For a transaction Ti to pass validation, for all previously committed transactions Tj (where TS(Tj)
< TS(Ti)), one of the following must be true:
Page 12 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
13. Tj completes all three phases before Ti starts its Read Phase → No overlap at all, no
conflict possible.
14. Tj completes its Write Phase before Ti starts its Write Phase, AND the Write Set of Tj
does not overlap with the Read Set of Ti → Ti did not read anything that Tj modified.
15. Tj completes its Read Phase before Ti completes its Read Phase, AND the Write Set of
Tj does not overlap with the Read or Write Sets of Ti → No conflict.
Check: T1's Write Set {A} overlaps with T2's Read Set {A}?
→ YES, A is in both. T2 must be rolled back!
If validation fails, all local changes are discarded. The transaction is restarted from Phase 1.
Advantages
• No locking — transactions never wait for locks, so there are no deadlocks
• High concurrency — many transactions can run simultaneously
• Best performance when conflicts are rare (read-heavy systems)
Disadvantages
• Wasted work: If a transaction fails validation after doing a lot of work, it must restart from
scratch
Page 13 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
• Starvation: A long transaction may keep failing validation and restarting (called livelock)
• Not efficient when conflicts are frequent — constant restarts degrade performance
Page 14 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
Best for: Bulk loading, write-heavy systems, or small tables where full scans are acceptable.
Best for: Read-heavy systems with frequent range queries and sorted access.
Page 15 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
• Search: Very fast for exact match queries — apply hash and go directly to the bucket
• Range queries: Not supported — records are spread randomly across buckets
• Insertion: Fast — apply hash and insert into the bucket
Best for: Exact match lookups, such as finding a record by primary key.
Block 1: [Dept 10, Aarav] [Dept 10, Bhanu] [Dept 10, Charan]
Block 2: [Dept 20, Divya] [Dept 20, Esha]
Employees in the same department are stored together
Best for: Queries that join two tables on the same key (e.g., Department JOIN Employee).
Page 16 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
Page 17 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
What is an Index?
An index is a separate, smaller file that contains key values and pointers (block addresses)
pointing to where the actual records are stored on disk. When a query searches for a specific
value, the database uses the index to find the location and goes directly to it.
Primary Index
A primary index is built on the ordering field of an ordered (sorted) file. The file is already sorted
by a specific key (called the ordering key), and the index is based on that same key.
Primary Index File (Sparse — one entry per block, assuming 3 records per block):
Index Key (EmpID) Pointer to Block
101 Block 1 (contains 101, 105, 110)
115 Block 2 (contains 115, 120, 125)
Page 18 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
To find Employee with EmpID = 120: Look at index → 115 points to Block 2 → scan Block 2 →
find 120. Only 1 disk block read instead of scanning all blocks.
Secondary Index
A secondary index is built on a non-ordering field — a field that is NOT used to physically sort
the records. It allows fast access to records based on a field other than the primary sort key.
Since the data file is not sorted by this field, the secondary index must be dense — it has one
entry for every single record (not just one per block), because records with the same secondary
key value may be scattered across many blocks.
Example: Building a secondary index on Department for the same Employee table:
To find all HR employees: Look at secondary index under 'HR' → pointers say Block 1 Row 1
and Block 2 Row 3 → go directly to those locations. No full scan needed.
Page 19 of 20
DBMS Study Notes — Part II | 3NF/BCNF · Decomposition · Granularity · Serializability · Validation · File Org
· Indexes
Summary:
Primary index is built on the field by which data is physically sorted — one entry per block.
Secondary index is built on any other field — one entry per record. A table can have only
one primary index but many secondary indexes. Both use pointers to locate records quickly
without full table scans.
Page 20 of 20