Weekly Exercises 01
Weekly Exercises 01
Week 1 Exercises
02 February 2021
1
DBMS Architecture
Question
2
Indexing
Question 1
3
Indexing Figure 17.4
A dense secondary index (with block pointers)
on a nonordering key field of a file.
Brief review before solving
2. Suppose that blocks can hold either ten records or 99 keys and 100 pointers. Also,
assume that the average B-tree node is 70% full; i.e., it will have 69 keys and 70
pointers. We can use B-trees as part of several different structures. For each structure
described below, determine
1. the total number of blocks needed for a 1,000,000-record file, and
2. the average number of disk I/O’s to retrieve a record given its search key.
You may assume nothing is in memory initially, and the search key is the primary key for
the records.
(a) The data file is a sequential file, sorted on the search key, with 10 records per block.
The B-tree is a dense index.
(b) The same as (a), but the data file consists of records in no particular order, packed 10
to a block.
(c) The same as (a), but the B-tree is a sparse index.
(d) Instead of the B-tree leaves having pointers to data records, the B-tree leaves hold
the records themselves. A block can hold ten records, but on average, a leaf block is
70% full; i.e., there are seven records per leaf block.
(e) The data file is a sequential file, and the B-tree is a sparse index, but each primary
block of the data file has one overflow block. On average, the primary block is full,
and the overflow block is half full. However, records are in no particular order within
a primary block and its overflow block. 8
B-Tree
Brief review before solving
2. Suppose that blocks can hold either ten records or 99 keys and 100 pointers. Also,
assume that the average B-tree node is 70% full; i.e., it will have 69 keys and 70
pointers. We can use B-trees as part of several different structures. For each structure
described below, determine
1. the total number of blocks needed for a 1,000,000-record file, and
2. the average number of disk I/O’s to retrieve a record given its search key.
You may assume nothing is in memory initially, and the search key is the primary key for
the records.
(b) The same as (a), but the data file consists of records in no particular order, packed
10 to a block.
The solution is same as (a) beacuse the ordering does not affect the no. of blocks or
pointers needed.
11
Indexing: Solution to Question 2c
2. Suppose that blocks can hold either ten records or 99 keys and 100 pointers. Also,
assume that the average B-tree node is 70% full; i.e., it will have 69 keys and 70
pointers. We can use B-trees as part of several different structures. For each structure
described below, determine
1. the total number of blocks needed for a 1,000,000-record file, and
2. the average number of disk I/O’s to retrieve a record given its search key.
You may assume nothing is in memory initially, and the search key is the primary key for
the records.
(c) The data file is a sequential file, sorted on the search key, with 10 records per block.
The B-tree is a sparse index.
Lowest level 1,000,000/10 = 100,000 blocks, for data
Leaf level 100,000/70 ≈ 1429 blocks In Sparse index, 100 000 data block require 100 000
pointers, i.e., one pointer or each block of data.
2nd level 1429/70 ≈ 21 blocks
The root 21/70 ≈ 1 block
Total no. of blocks = 100,000 + 1429 + 21 + 1 = 101,451
Average no. of disk-operations = 4
12
Indexing: Solution to Question 2d
2. Suppose that blocks can hold either ten records or 99 keys and 100 pointers. Also,
assume that the average B-tree node is 70% full; i.e., it will have 69 keys and 70
pointers. We can use B-trees as part of several different structures. For each structure
described below, determine
1. the total number of blocks needed for a 1,000,000-record file, and
2. the average number of disk I/O’s to retrieve a record given its search key.
You may assume nothing is in memory initially, and the search key is the primary key for
the records.
(d) Instead of the B-tree leaves having pointers to data records, the B-tree leaves hold
the records themselves. A block can hold ten records, but on average, a leaf block is
70% full; i.e., there are seven records per leaf block.
Lowest/Leaf level 1,000,000/7 = 142,858 blocks Leaves hold the data records, and data records are
grouped into 70% of 10 or 7, while the pointers,
2nd level 142,858/70 ≈ 2041 blocks in other tree levels, are grouped into 70% of 100
3rd level 2041/70 ≈ 30 blocks or 70.
Average no. of disk-operations = 3 (for B-tree levels) + 1 for primary block + 1/3 of
the time for overflow block = 13/3 14
Quiz on PostgreSQL Indexing
• Exercise/test
Take the 3-minute-test on
https://use-the-index-luke.com/3-minute-test/postgresql
It has 5 exercises. The solutions are explained after you try them! And you can find
many examples in the book and on the Internet.
15
Questions? Please email to
smrashid@math.uio.no
Thank you