Chapter- 14- Index structures for files Database Design.
-
Upload
sharleen-mckenzie -
Category
Documents
-
view
225 -
download
0
Transcript of Chapter- 14- Index structures for files Database Design.
![Page 1: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/1.jpg)
Chapter- 14- Index structures for files
Database Design
![Page 2: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/2.jpg)
1
Outline
• Introduction• Types of Single-Level Ordered Indexes.
• Primary Indexes.• Clustering Indexes.• Secondary indexes.
![Page 3: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/3.jpg)
2
Introduction
Indexes are additional auxiliary access structures with typically provide:
faster access to datamakes it more efficient to search for a record in the data
file.
One form of an index is a file of entries: < field value, pointer to record > , which is ordered by field value
The index file usually occupies considerably less disk blocks than the data file because its entries are much smaller
![Page 4: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/4.jpg)
2
Types of Indexes
Single-Level IndexesPrimary.Secondary.Clustering.
Multi-Level IndexesISAMB TreesB+ Trees
![Page 5: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/5.jpg)
2
Single-Level Indexes
A Primary Index: is specified on the ordering key field where each tuple has a unique value.
A Clustering Index: is specified on the ordering key field where each tuple DOES NOT have a unique value in that field.
A Secondary Index :is specified on a NON-ORDERING Field of the file.
![Page 6: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/6.jpg)
Primary Index
A Primary Index is an ordered file whose records of fixed length of two parts:The first field is the same data type of the primary key of a file block of the data file and the second field is file block pointer (block address)
The Anchor Record or Block anchor is the first record in a file block. This is where the value for the first field of the primary index come from along with the respective address of that block.
![Page 7: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/7.jpg)
![Page 8: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/8.jpg)
ExampleSuppose that we have an ordered file with r=30,000
record stored on a disk with block size B=1024 bytes.File records are of fixed size and are unspanned, with
record length R= 100 bytes.Calculate the number of blocks needed for this file
and the blocking factor(number of records for each block).
Blocking Factor bfr= B/R = 1024/100 = 10 records per block
The number of blocks b = r/bfr = 30,000/10 = 3000 blocksA binary search on the data file would need approximately
Log2b = Log2 3000 = 12 block accesses
![Page 9: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/9.jpg)
Example (cont.)Suppose that the ordering key field of
the file V=9 bytes long , a block pointer is P=6 bytes long. And we have
constructed a primary index for the file.The size of the each index entry is Ri=
(9+6) = 15 bytes .Blocking factor for the index is bfri =
B/Ri = 1024/15 = 68 entries per blockThe total number of the index entry ri is
equal to the number of blocks in the data file = 3000
![Page 10: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/10.jpg)
Example (cont)The number of index blocks is bi = ri/bfri =
3000/68 = 45 blocksTo perform a binary search on the index file
would need Log2bi = Log245 = 6 block accesses + 1 additional block access to
the data in the data file .
![Page 11: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/11.jpg)
Clustering Index
Clustering Indexes are used when the ordering index is a field where each value is not unique.
An entry in the clustering index is composed of a SINGLE entry for each distinct value in the clustering field and its respective file block pointer.
![Page 12: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/12.jpg)
Data file
Dnumber NAME SSN Birthdate JOB SALARY
Clustering Field
INDEX File( <ki,Pi,> entries
CLUSTERING Field Value
Block pointer
![Page 13: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/13.jpg)
![Page 14: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/14.jpg)
Secondary Index
A Secondary Index is an ordered file with two fields.
The first is of the same data type as some nonordering field and the second is either a block or a record pointer.
The secondary index may be on a field which is a candidate key and has a unique value in every record, or a nonkey with duplicate values
![Page 15: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/15.jpg)
![Page 16: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/16.jpg)
Secondary Index
Since there is no guarantee that the value will be unique the previous index method will not work.
Option 1: Include index entries for each record. This results in multiple entries of the same value.
Option 2: Use variable length records with a pointer to each block/record with that value.
Option 3: Have the pointer; point to a block or chain of blocks that contain pointers to all the blocks/records that contain the field value.
![Page 17: Chapter- 14- Index structures for files Database Design.](https://reader035.fdocuments.us/reader035/viewer/2022062221/56649f0c5503460f94c1fb68/html5/thumbnails/17.jpg)