Download presentation
Presentation is loading. Please wait.
Published byEvelyn Stokes Modified over 9 years ago
1
Chapter 61 Chapter 6 Index Structures for Files
2
Chapter 62 Indexes Indexes are additional auxiliary access structures with typically provide either faster access to data or secondary access paths without effecting the physical storage of the data. They are based on indexing field(s) that are used to construct the index.
3
Chapter 63 Types of Indexes Single-Level Indexes –Primary –Secondary –Clustering Multi-Level Indexes –ISAM –B Trees –B+ Trees
4
Chapter 64 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.
5
Chapter 65 Primary Indexes A Primary Index is constructed 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. 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.
6
Chapter 66
7
7 How to Efficiently Handle Insertions & Deletions when all the blocks FULL?
8
Chapter 68 Clustering Indexes Clustering Indexes are used when the ordering index is not a field where each value is 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.
9
Chapter 69
10
10
11
Chapter 611 Secondary Indexes 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. If the entries in this nonordering field must be unique this field is sometime referred to as a Secondary Key. This results in a dense index.
12
Chapter 612
13
Chapter 613 Secondary Index on Non-Key Field 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.
14
Chapter 614
15
Chapter 615 Multilevel Indexes A Multilevel Index is where you construct an Second- Level index on a First-Level Index. Continue this process until the entire index can be contained in a Single File Block. This allows much faster access than binary search because at each level the size of the index is reduced by the fan out factor. Rather just by 2 as in binary search.
16
Chapter 616
17
Chapter 617 Multilevel Indexes Using Search Trees, B-Trees & B+ Trees A Search Tree of order p differs from a Multilevel Index in that each node contains a most p - 1 search values and p pointers. There is no requirement that the Search Tree be Balanced.
18
Chapter 618
19
Chapter 619 B-Trees B-Trees address the problems with Search Trees in that they have the additional constraint that they be balanced and they contain pointers to data records. Each B-Trees is made up of at most P tree pointers and P-1 field values K and data pointers Pr.
20
Chapter 620
21
Chapter 621
22
Chapter 622 B-Tree Rules,..., P q-1,, P q > Within each node K 1 < K 2 <...< K q-1 For each search value X in the subtree pointed to by P i the following hold true: When i = 1 : X < K i When 1< i < q :K i-1 < X < K i When i = q -1: K i < X
23
Chapter 623 B-Tree Rules (con’t) Each node has at most p tree pointers. Each node, except the root and leaf nodes, has at least (p/2) tree pointers. The root node has at least two tree pointers unless it is the only node in the tree. A node with q tree pointers, q p, has q -1 search key field values. All leaf node are at the same level and all their tree pointers are null.
24
Chapter 624 Example 4 Search Field V=9 bytes Disk Block B=512 bytes Record Pointer P r = 7 bytes Block Pointer P = 6 bytes Compute the number of block pointers p that can be contained in one block where siblings are linked. (p*P) + ((p-1) *(P r +V)) + P < B
25
Chapter 625 Example 5 Non-ordering search field. Each node is 69% full in B-Tree Based on Example 4 compute the average fan- out factor compute the number of nodes, data entries and Block pointers (Root to Level 3).
26
Chapter 626 B+ - Trees Unlike B-Trees B+ - Trees are constructed of two different nodes: Internal Nodes where: – –For each internal node K 1 < K 2 <... < K q-1
27
Chapter 627 –For all search field values X pointed by P i When i = 1 : X < K i When 1< i < q :K i-1 < X K i When i = q -1: K i < X –Each Internal node has at most p tree pointers. –Each node, except the root and leaf nodes, has at least (p/2) tree pointers. The root node has at least two tree pointers if it is an internal node. –An internal node with q pointers, q p, has q-1 search field values.
28
Chapter 628 B+-Tree Leaf Nodes Each leaf is of the form,, …,, P next > Within each leaf node, K 1 < K 2 <…<K q-1 Each Pr i is a data pointer that points to the block/record that contains K i. Each Leaf Node has at least (p/2) values. All leaf nodes are at the same level.
29
Chapter 629
30
Chapter 630 Computing p & p leaf for B+ Trees Calculate p for an internal & leaf node: – V = 9 bytes –P r = 7 bytes –P = 6 bytes (p * 6) + ( (p - 1) * 9) < 512 (p leaf * (P r + V)) + 6 < 512
31
Chapter 631 Insert record r=(k,Pr) with key K in B+ Tree begin locate leaf n to which K belongs; if n has < Pleaf entries then insert (K, Pr) in proper order into n, and EXIT else ‘temporarily’ insert (K,Pr) in proper order into n; allocate a new leaf new; keep first Pleaf +1)/2 entries of n in n; assign the remaining entries to new; recursively insert new as a child of the parent of n. To split an internal node that overflows use P instead of Pleaf
32
Chapter 632
33
Chapter 633
34
Chapter 634
35
Chapter 635
36
Chapter 636
37
Chapter 637
38
Chapter 638
39
Chapter 639 Delete record r=(k,Pr) with key K in B+ Tree locate leaf n to which K belongs; if n has > Pleaf/2 entries then remove (K,Pr) from n, adjust parents as needed and EXIT else if left sibling ( if exists) of n has > Pleaf/2 entries remove (k, Pr) from n and move largest entry of its left sibling to n, adjust parents as needed and EXIT else if right sibling ( if exists) of n has > Pleaf/2 entries remove (k, Pr) from n move smallest entry of its left sibling to n, adjust parents as needed and EXIT
40
Chapter 640 Delete record in B+ Tree (con’t) else if exist left sibling of n then remove (k, Pr) from n; assign remaining entries of n to its left sibling; recursively delete n; else remove (k, Pr) from n; assign remaining entries of n to its right sibling; recursively delete n;
41
Chapter 641
42
Chapter 642
43
Chapter 643
44
Chapter 644
45
Chapter 645
46
Chapter 646 Indexes On Multiple Keys Up until now we have limited our discussion to accessing file based on single attributes. Unfortunately, in the real world composite keys exist along with queries on multiple fields and have to be dealt with.
47
Chapter 647 Accessing Based on Multiple Attribute Conditions If any of the attributes in the search condition have an index associated with it you may use that index to limit your search. If more than one of the attributes in the search condition have indexes associated with them you can find the intersection of those indexes to limit your search.
48
Chapter 648 Creating an Ordered Index on Multiple Attributes When you create an Ordered Index on multiple attributes; it is constructed on the Order in which the attributes are specified. This means that if we constructed an index on DNO, SUPERSSN and BDATE in ascending order; first it would be ordered by DNO (1-5). Then within each DNO i.e. 4 they would be ordered by SUPERSSN and so on.
49
Chapter 649 Partitioned Hashing Partitioned hashing is an extension of static external hashing that allows access on multiple keys. It assigns specific fields of the hash address to each attribute so the value of each attribute that makes up the index is hashed to generate that portion of the bit pattern to be used and the combined pattern is assembled.
50
Chapter 650 Grid Files With Grid Files you create a N-Dimensional array for N attributes. Each attribute is divided into table which will map it to the coordinate of its respective dimension While this method works well with ranges its overhead can be expensive.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.