0% found this document useful (0 votes)
16 views

index3(1)

Uploaded by

Mx A
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

index3(1)

Uploaded by

Mx A
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Index Structure

 Single-level Indexes
 Primary Indexes
 Clustering Indexes
 Secondary Indexes
 Hash-Based Index
 Multi-level Indexes / Tree-Based Index

1
Hashed-Based Indexing

 Good for equality search: hashing quickly


finds records that have a given search key
value
 e.g., Select Name
From Employees
Where SSN = 123456789; (or Where DNO = 5)
 The records of a file are grouped in buckets
 Index is a collection of buckets. Bucket =
primary page plus zero or more overflow
pages (additional pages linked in a chain)
Hashed-Based Indexing Cont.
Hashed-Based Indexing Cont.

 Hashing function h: h(r) = bucket in which


record r belongs. h looks at the search key
fields of r
 A common hash function is h(K) = K mod M,
where K is the search key value
 Given a bucket number, a hash-based index
allows to retrieve the primary page for the
bucket in 1 or 2 I/Os
Hashed-Based Indexing Cont.

 If Alternative (1) is used, the buckets contain the


data records; otherwise, they contain <key, rid> or
<key, rid-list> pairs:
Why Multi-Level Indexes?
 In all the single-level indexing schemes we have seen
so far, we have:
 An ordered index file
 The size of an index file depends on the index type (i.e.,
primary, clustering, or secondary)
 Binary search is applied to the index file
 to locate pointers Pi to disk blocks having a specific index
filed value Ki
 Binary search requires log2Bi
 In an index file of size Bi blocks, each step of binary search
halves the number of remaining index blocks to search

 Can we do better than log2Bi ?!!

6
Example

What kind of index to build on this key field?


If index bfr = 4, how many index blocks?
Answer: see next slide..

7
Example
What kind of index to build on this key field? Primary index
If index bfr = 4, how many index blocks? 4 blocks
To find a record: Binary search the 4 index blocks
Can we do better?

8
Create an index on the index!

9
Multi-Level Indexes
 Because a single-level index is an ordered
file: create a primary index to the index itself!
 original index file is called first-level index
(base)

 index to index is called the second-level index

 Repeat the process until all entries of the top


level fit in one disk block

 A multi-level index can be used on any type of


first-level index: primary, secondary, clustering

10
Multi-level Index

11
Multi-level Indexing Cont.

 Fan-out (fo): of the multi-level index is the


blocking factor bfri of the index
 Multi-level index reduces the searching
space of the index by a factor of fo at each
step
 Searching a multi-level index requires
approximately logfobi block accesses
Multi-level Indexing

1st (base) level

145140134128 123118112107 102 96 90 85 80 71 36 55 51 44 39 35 24 15 8 2

Data Blocks

13
Multi-level Indexing

3rd (top) level


107 2

2nd level
128 107 85 55 35 2

1st (base) level

145140134128 123118112107 102 96 90 85 80 71 36 55 51 44 39 35 24 15 8 2

Data Blocks

15
Multi-level Indexing Cont.

 If the first level has r1 entries, then the first


level needs 𝑟1 /𝑓𝑜 blocks = number of
entries r2 needed at the second level
 The number of third-level entries r3 = ?
 This is repeated until all entries at level t fit in
one block (top index level)
 Each level reduces the entries of the previous
level by a factor of fo
 A multi-level index with r1 first-level entries will
have t = 𝑙𝑜𝑔𝑓𝑜 (𝑟1) levels
Multi-level Index: Example
Search for 24
Number of accessed blocks:
3 index blocks
+ 1 data block
= 4 blocks in total
107 2

128 107 85 55 35 2

145140134128 123118112107 102 96 90 85 80 71 66 55 51 44 39 35 24 15 8 2

18
Multi-level Index: Example
Search for 140
Number of accessed blocks:
3 index blocks
+ 1 data block
= 4 blocks in total
107 2

128 107 85 55 35 2

145140134128 123118112107 102 96 90 85 80 71 36 55 51 44 39 35 24 15 8 2

20
Index File vs. Data File!
Data file

Index file

21
Index File vs. Data File!
Data file
Index file

22
Multi-level index as a tree
 Multi-level index is a form of search tree
 Each node has pointers
 By following a pointer, we restrict our search to a
subtree and ignore all other nodes
 The number of pointers (fan-out ) is the index blocking
factor which is the number of children a node has

 But the multi-level indexing we have seen so far is


static!

23
Dynamic Data

 A multi-level index is a form of search tree


 Insert/delete of an index entry is a problem because:
 every level of the index is ordered
 what happens when inserting new entry 82?
24

You might also like