Record storage and page layout in DBMS Theory - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When storing records in a database, how fast we can find or add data depends on how records are arranged on pages.
We want to understand how the time to access records grows as the number of records increases.
Analyze the time complexity of searching for a record in a page-based storage system.
-- Assume a page stores multiple records
-- To find a record, the system scans records in the page one by one
FOR each record IN page LOOP
IF record matches search_key THEN
RETURN record;
END IF;
END LOOP;
This code scans records sequentially on a page to find a matching record.
Look for repeated actions that affect time.
- Primary operation: Scanning each record in the page one by one.
- How many times: Up to the number of records in the page (n times).
As the number of records in a page grows, the time to find a record grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Up to 10 record checks |
| 100 | Up to 100 record checks |
| 1000 | Up to 1000 record checks |
Pattern observation: The time grows roughly in direct proportion to the number of records scanned.
Time Complexity: O(n)
This means the time to find a record grows linearly with the number of records on the page.
[X] Wrong: "Searching a record on a page always takes the same time no matter how many records are there."
[OK] Correct: Because the system checks records one by one, more records mean more checks and more time.
Understanding how record layout affects search time helps you explain database performance clearly and shows you grasp practical data storage concepts.
What if the records on a page were stored in a sorted order? How would that change the time complexity of searching?
Practice
record storage in a database system?Solution
Step 1: Understand record storage concept
Record storage arranges data records into pages on disk to optimize reading and writing.Step 2: Identify the main purpose
This organization helps the database system access data efficiently by reading whole pages instead of individual records.Final Answer:
To organize data into fixed-size pages on disk for efficient access -> Option AQuick Check:
Record storage = organizing data in pages [OK]
- Confusing record storage with encryption
- Thinking it manages user interfaces
- Assuming it handles network connections
page layout in database storage?Solution
Step 1: Define page layout
Page layout specifies how records fit and are organized inside a fixed-size page on disk.Step 2: Match description to options
The structure defining how records are arranged inside a page correctly states it defines record arrangement inside a page, unlike other unrelated options.Final Answer:
The structure defining how records are arranged inside a page -> Option DQuick Check:
Page layout = record arrangement inside page [OK]
- Confusing page layout with encryption
- Mixing it up with network protocols
- Thinking it relates to user interfaces
Solution
Step 1: Convert page size to bytes
4 KB = 4 x 1024 = 4096 bytes.Step 2: Calculate number of records per page
Number of records = 4096 bytes / 400 bytes per record = 10.24, so only 10 full records fit.Final Answer:
10 -> Option BQuick Check:
4096 รท 400 = 10 records [OK]
- Using 1000 instead of 1024 for KB
- Rounding up instead of down
- Ignoring page overhead but still rounding incorrectly
Solution
Step 1: Calculate usable space in the page
Page size = 8 KB = 8192 bytes. Header = 512 bytes. Usable space = 8192 - 512 = 7680 bytes.Step 2: Calculate number of records
Each record = 1 KB = 1024 bytes. Number of records = 7680 / 1024 = 7.5, so only 7 full records fit.Final Answer:
7 -> Option AQuick Check:
Usable space รท record size = 7 records [OK]
- Ignoring header size
- Rounding up instead of down
- Using 1000 bytes for KB instead of 1024
Solution
Step 1: Understand variable-length record challenges
Variable-length records vary in size, so fixed slots cause wasted space due to padding.Step 2: Identify suitable page layout
Variable-length slots with a directory allow storing records compactly and tracking their positions efficiently.Step 3: Evaluate other options
Fixed-length slots waste space; rejecting variable sizes is impractical; multiple small pages add overhead.Final Answer:
Variable-length slots with a directory to track record offsets -> Option CQuick Check:
Variable-length records = variable slots + directory [OK]
- Choosing fixed-length slots causing wasted space
- Ignoring variable record sizes
- Thinking multiple small pages improve efficiency
