Docsity

Indexing and Searching Techniques: Single and Multilevel Indexes, Study Guides, Projects, Research of Introduction to Database Management Systems

Partial preview of the text

Download Indexing and Searching Techniques: Single and Multilevel Indexes and more Study Guides, Projects, Research Introduction to Database Management Systems in PDF only on Docsity!

Announcements

•^

Today– Single level index review– Multilevel index

-^

Reading assignment:– Chapter 5 and Sections 6.0-6.

Program 1 post-mortem

•^

I am in the process of grading it

-^

Harshness of auto grading– Does not compile

Æ

grade = 0

•^

We will have some way to replace lowestprogram

-^

Please follow instructions exactly for turning insubsequent assignment

Primary Index

•^

Index contains one index entry / block– Example index entry for a primary index on student #

  • <student# = 4173, blockID = 937>

•^

Time to access in I/O operations– Without index: log

B 2

  • With index: log

2

B

idx

  • 1

The student # of the first record on block 937 is 4137

The number ofblocks in the file

The number ofblocks in index

Clustered Index

•^

Index contains one entry / unique value ofindexing field– Example index entry for clustered index on major

  • <major = “CompSci”, blockID = 937>

•^

Time to access in I/O operations– Without index: log

B 2

  • With index: log

2

B

idx

  • 1

The first block with a record whose major is CompSci has blkID=

The number ofblocks in the file

The number ofblocks in index

Example 1 and 2 in Chapter 14

•^

Setting

file w/ 30,000 fixed length records of 100

bytes on 1024 byte blocks– Records / block = 10– # blocks in file = 3,000– Search for key w/o idx: log2 3000 = about 12

-^

Make index on 9 byte ordering key, block ID is 6bytes– 68 index entries / block, 3,000 total index entries– 45 blocks in the index– Search for key w/ index = 1+log2 45 = 7 I/Os

Example (continued)

•^

Now search for non-ordering key:– Average is 1500 block reads

-^

Construct secondary key on 9 byte non orderingkey field:– Index entry still 15 bytes, 68 entries / block– But we need entry for each of the 30,000 records

  • Need 442 blocks for index.
    • Binary search is log2 442 = 9 block reads + 1 to get

the record is 10.

Multilevel Indexes

•^

Consider a clustered index on a non-key field

-^

The index itself is an ordered file of(value, blockPtr) pairs where value is a key field

-^

We can thus construct a primary index on“value”

-^

Add levels until the index fits in one block

Inserts / Deletes are Problematic

•^

In general, inserts and deletes to the filerequires updating the index

-^

Each level of the index is a physically orderedfile thus updates are expensive

-^

One solution: leave some space on each indexfor inserting new index entries

Æ

B+ trees

B+ Trees

•^

B+ trees are the most popular implementation ofdynamic multilevel indexes

-^

There are two types B+ tree index blocks–

Internal nodes:

contain index field values (used to

guide the search) and pointers blocks in lower levelsof the B+ tree (tree pointers)

Leaf nodes:

contain values and matching RIDs

B+ Tree Properties

•^

A B+ tree is always balanced (ie, distance fromthe root to leaf is the same for each leaf)

-^

Let

p

be the maximum number of tree pointers

on an internal block– Other than root, each internal page has at least

ceil(p/2) tree pointers

  • A block with

q

tree pointers has

q-

search field

values

•^

Key aspect of B+ trees are graceful algorithmsfor handling insertions and delete