File Organizations
R & G - Chapter 9
Architecture of a DBMS
Completed
And We’ll Visit
You are Here
Database Management
System
Database
Query Parsing�& Optimization
Relational Operators
Files and Index Management
Buffer Management
Disk Space Management
SQL Client
Recall: Heap Files
Recall: Multiple File Organizations
Many alternatives exist, each good in some situations and less so in others.
This is a theme in DB systems work!
Bigger Questions
Goals
COST MODEL AND ANALYSIS
Cost Model for Analysis
Block 1
Block 2
…
Block B
Record 1
Record 2
…
Record R
More Assumptions
Extra Challenge
Heap Files & Sorted Files
2, 5
1, 6
4, 7
3, 10
8, 9
Heap File
1, 2
3, 4
5, 6
7, 8
9, 10
For illustration, records are just integers
Sorted File
Cost of Operations: Scan?
| Heap File | Sorted File |
Scan all records | | |
Equality Search | | |
Range Search | | |
Insert | | |
Delete | | |
Scan All Records
2, 5
1, 6
4, 7
3, 10
8, 9
Heap File
1, 2
3, 4
5, 6
7, 8
9, 10
Sorted File
Cost of Operations: Scan Cost
| Heap File | Sorted File |
Scan all records | B*D | B*D |
Equality Search | | |
Range Search | | |
Insert | | |
Delete | | |
Cost of Operations: Equality Search?
| Heap File | Sorted File |
Scan all records | B*D | B*D |
Equality Search | | |
Range Search | | |
Insert | | |
Delete | | |
Find Key 8: Heap File
Heap File
2, 5
1, 6
4, 7
3, 10
8, 9
Find Key 8: Sorted File
Sorted File
1, 2
3, 4
5, 6
7, 8
9, 10
Average Case Binary Search
Expected Number of Reads: 1 (1 / B) + 2 ( 2 / B) + 3 (4 / B) + 4 (8 / B)
Average Case Binary Search cont
Expected Number of Reads: 1 (1 / B) + 2 ( 2 / B) + 3 (4 / B) + 4 (8 / B)
1 IO
2 IOs
3 IOs
4 IOs
Cost of Operations: Equation Search Cost
| Heap File | Sorted File |
Scan all records | B*D | B*D |
Equality Search | 0.5*B*D | (log2B)*D |
Range Search | | |
Insert | | |
Delete | | |
Cost of Operations: Range Search?
| Heap File | Sorted File |
Scan all records | B*D | B*D |
Equality Search | 0.5*B*D | (log2B)*D |
Range Search | | |
Insert | | |
Delete | | |
Find Keys Between 7 and 9: Heap File
Heap File
2, 5
1, 6
4, 7
3, 10
8, 9
Find Keys Between 7 and 9: Comparison
Heap File
2, 5
1, 6
4, 7
3, 10
8, 9
Sorted File
1, 2
3, 4
5, 6
7, 8
9, 10
Cost of Operations: Range Search Cost
| Heap File | Sorted File |
Scan all records | B*D | B*D |
Equality Search | 0.5*B*D | (log2B)*D |
Range Search | B*D | ((log2B)+pages)*D |
Insert | | |
Delete | | |
Cost of Operations: Insert?
| Heap File | Sorted File |
Scan all records | B*D | B*D |
Equality Search | 0.5*B*D | (log2B)*D |
Range Search | B*D | ((log2B)+pages)*D |
Insert | | |
Delete | | |
Insert 4.5: Heap File
Heap File
2, 5
1, 6
4, 7
3, 10
8, 9
4.5,_
Insert 4.5: Heap VS Sorted File
Heap File
2, 5
1, 6
4, 7
3, 10
8, 9
4.5,
Sorted File
1, 2
3, 4
5, 6
7, 8
9, _
Insert 4.5: Heap Vs Sorted Pt 2
1, 2
3, 4
5, 6
7, 8
9, 10
2, 5
1, 6
4, 7
3, 10
8, 9
4.5,
10, _
Heap File
Sorted File
4.5, 5
6, 7
8, 9
Cost of Operations: Insert Cost
| Heap File | Sorted File |
Scan all records | B*D | B*D |
Equality Search | 0.5*B*D | (log2B)*D |
Range Search | B*D | ((log2B)+pages)*D |
Insert | 2*D | ((log2B)+B)*D |
Delete | | |
Cost of Operations: Delete?
| Heap File | Sorted File |
Scan all records | B*D | B*D |
Equality Search | 0.5*B*D | (log2B)*D |
Range Search | B*D | ((log2B)+pages)*D |
Insert | 2*D | ((log2B)+B)*D |
Delete | | |
Delete 4.5: Heap File
Heap File
2, 5
1, 6
4, 7
3, 10
8, 9
4.5,
Delete 4.5: Heap File Vs Sorted File
Heap File
2, 5
1, 6
4, 7
3, 10
8, 9
Sorted File
1, 2
3, 4
4.5, 5
6, 7
8, 9
10, _
_
Delete 4.5: Heap File Vs Sorted File Pt 2
Heap File
2, 5
1, 6
4, 7
3, 10
8, 9
Sorted File
1, 2
3, 4
__, 5
6, 7
8, 9
10, _
7, 8
9, 10
Cost of Operations Complete
| Heap File | Sorted File |
Scan all records | B*D | B*D |
Equality Search | 0.5*B*D | (log2B)*D |
Range Search | B*D | ((log2B)+pages)*D |
Insert | 2*D | ((log2B)+B)*D |
Delete | (0.5*B+1)*D | ((log2B)+B)*D |
Cost of Operations Complete Pt 2
| Heap File | Sorted File |
Scan all records | B*D | B*D |
Equality Search | 0.5*B*D | (log2B)*D |
Range Search | B*D | ((log2B)+pages)*D |
Insert | 2*D | ((log2B)+B)*D |
Delete | (0.5*B+1)*D | ((log2B)+B)*D |