File Organizations and Indexing: R&G Chapter 8
File Organizations and Indexing: R&G Chapter 8
R&G Chapter 8
Context
Query Optimization
and Execution
Relational Operators
Files and Access Methods
Buffer Management
Disk Space Management
DB
Sorted Files:
Files compacted after deletions.
Selections on search key.
Cost of
Operations
Heap File
Scan all
records
Equality
Search
Range
Search
Insert
Delete
Sorted File
Clustered File
Cost of
Operations
Scan all
records
Equality
Search
Range
Search
Insert
Delete
Heap File
Sorted File
BD
BD
Clustered File
Cost of
Operations
Heap File
Sorted File
Scan all
records
BD
BD
Equality
Search
0.5 BD
(log2 B) * D
Range
Search
Insert
Delete
Clustered File
Cost of
Operations
Heap File
Sorted File
Scan all
records
BD
BD
Equality
Search
0.5 BD
(log2 B) * D
Range
Search
BD
[(log2 B) +
#match pg]*D
Insert
Delete
Clustered File
Cost of
Operations
Heap File
Sorted File
Scan all
records
BD
BD
Equality
Search
0.5 BD
(log2 B) * D
Range
Search
BD
[(log2 B) +
#match pg]*D
Insert
2D
((log2B)+B)D
(because R,W 0.5)
Delete
Clustered File
Cost of
Operations
Heap File
Sorted File
Scan all
records
BD
BD
Equality
Search
0.5 BD
(log2 B) * D
Range
Search
BD
[(log2 B) +
#match pg]*D
Insert
2D
((log2B)+B)D
Delete
0.5BD + D
((log2B)+B)D
(because R,W 0.5)
Clustered File
Indexes
Sometimes, we want to retrieve records by
specifying the values in one or more fields, e.g.,
Find all students in the CS department
Find all students with a gpa > 3
An index on a file is a disk-based data structure
that speeds up selections on the search key
fields for the index.
Any subset of the fields of a relation can be
the search key for an index on the relation.
Search key is not the same as key (e.g.
doesnt have to be unique ID).
Can have multiple (different) indexes per file.
E.g. sort by age, with an index on salary and
name.
Index Breakdown
Index Data Structure
Tree-based, hash-based, other
What can the index speed up, and how much?
Data structures
What kinds of selections do they support?
Selections of form field <op> constant
Equality selections (op is =)
Range selections (op is one of <, >, <=, >=,
BETWEEN)
Secondary index
e.g., eye color, year of birth, etc.
Duplicate support required
Use RID or primary key to refer to record?
only)
<k, rid of matching data record>
<k, list of rids of matching data
records>
Index Classification
CLUSTERED
Index entries
direct search for
data entries
Data entries
UNCLUSTERED
Data entries
(Index File)
(Data file)
Data Records
Data Records
Clustered Cons
Expensive to maintain (on the fly or
sloppy with reorganization)
Pages tend to be only 2/3 full!
Cost of
Operations
Heap File
Sorted File
Clustered File
Scan all
records
BD
BD
1.5 BD
Equality
Search
0.5 BD
(log2 B) * D
(logF 1.5B) * D
Range
Search
BD
[(log2 B) +
#match pg]*D
[(logF 1.5B) +
#match pg]*D
Insert
2D
((log2B)+B)D
((logF 1.5B)+1) *
D
Delete
0.5BD + D
((log2B)+B)D
(because R,W 0.5)
((logF 1.5B)+1) *
D
11
12,10
12
12,20
13,75
<age, sal>
10,12
20,12
75,13
10
cal 11
80
joe 12
20
sue 13
75
12
13
<age>
10
Data records
sorted by name
80,11
<sal, age>
20
75
80
<sal>
Data entries
sorted by <sal>
Summary
File Layer manages access to records in pages.
Record and page formats depend on fixed vs. variablelength.
Free space management an important issue.
Slotted page format supports variable length records
and allows records to move on page.
Summary (Contd.)
Data entries in index can be actual data records, <key,
rid> pairs, or <key, rid-list> pairs.
Choice orthogonal to indexing structure (i.e., tree, hash,
etc.).