1 / 46

Chap.10 Indexed Sequential File Access and Prefix B+ Trees

File Structures by Folk, Zoellick, and Ricarrdi. Chap.10 Indexed Sequential File Access and Prefix B+ Trees. 서울대학교 컴퓨터공학부 객체지향시스템연구실 SNU-OOPSLA-LAB 교수 김 형 주. Chapter Objectives. Introduce indexed sequential files

manasa
Télécharger la présentation

Chap.10 Indexed Sequential File Access and Prefix B+ Trees

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. File Structures by Folk, Zoellick, and Ricarrdi Chap.10 Indexed Sequential File Access and Prefix B+ Trees 서울대학교 컴퓨터공학부 객체지향시스템연구실 SNU-OOPSLA-LAB 교수 김 형 주 SNU-OOPSLA Lab.

  2. Chapter Objectives • Introduce indexed sequential files • Describe operations on a sequence set of blocks that maintains records in order by key • Show how an index set can be built on top of the sequence set to produce an indexed sequential file structure • Introduce the use of a B-tree to maintain the index set, thereby introducing B+ trees and simple prefix B+ trees • Illustrate how the B-tree index in a simple prefix B+ tree can be of variable order, holding a variable number of separators • Compare the strengths and weakness of B+ trees, simple prefix B+ trees, and B-trees SNU-OOPSLA Lab.

  3. Contents • 10.1 Indexed Sequential Access • 10.2 Maintaining a Sequence Set • 10.3 Adding a Simple Index to the Sequence Set • 10.5 The Contents of the Index: Separators Instead of Keys • 10.6 The Simple Prefix B+ Tree Maintenance • 10.7 Index Set Block size • 10.8 Internal Structure of the Index Set Blocks: A variable-order B-Tree • 10.9 Loading a Simple Prefix B+ Tree • 10.10 B+ Trees • 10.11 B-Trees, B+ Trees, and Simple Prefix B+ Trees in Perspective SNU-OOPSLA Lab.

  4. 10.1 Indexed Sequential Access • Two alternative views • indexed : records are indexed by keys • no good for sequential processing • sequential : records can be accessed sequentially • not good for access, insert, delete records in random order • In chap 9, we see B tree and now we want derive Indexed + Sequential ==> B+ tree with help of the idea of the sequence set • Sequential file ==> Indexed Sequential file ==> B+ tree • Indexed-Sequential file = Indexed Sequential Access Method (ISAM) SNU-OOPSLA Lab.

  5. R main memory a secondary memory 61 b c 10 20 50 61 101 d e f g h i 1 3 10 11 20 30 40 45 51 55 57 65 70 101 120 150 A B A C D D C A A D B E B C A D part description records 50 60 61 primary key PART # D B A PART-Type Example : Indexed sequential structure (when using overflow chain) Overview : ISAM File SNU-OOPSLA Lab.

  6. Overview : ISAM File (2) • Compared with ordered relative file • Ordered on a key, like ordered relative file • Can be accessed by an index, structure that contains information on where a record with a given key is located (usually intermingled with blocks of records) • Tree search of an index replaces binary search of ordered relative files SNU-OOPSLA Lab.

  7. Index Block Data Block Data Block Data Block . . . Overflow Data Block Overflow Data Block Overflow Data Block Indexed Sequential Files • Block types • Index Block • Primary Data Block • Overflow Data Block SNU-OOPSLA Lab.

  8. Indexed Sequential Files :Retrieval • Retrieve parts_file where part# = 60 • Primary Key search : nodes R,a,b,g accessed • 3 primary block access, 1 overflow block accessed • Retrieve parts_file where part# = 101 and part_type = C (overqualified) • Primary Key search : nodes R,a,c,h accessed • 3 primary block accesses • Block “access”es are really block fetches. The blocks may be in main memory buffers so that actual block accesses aren’t performed SNU-OOPSLA Lab.

  9. Indexed Sequential Files : Retrieval(2) • Retrieve part_file where part#= 101 or part_type = C • Scan : node R,d,e,f,g,h,I accessed • 6 primary block “accesses” • overflow block “accesses” SNU-OOPSLA Lab.

  10. 1 2 3 R a 61 b c 10 20 50 61 101 d e f g h i 1 3 10 11 20 30 40 45 51 55 57 65 70 101 120 150 A B A C D D C A A D B E B C A D 50 60 61 D B A Retrieval of Indexed sequential structure SNU-OOPSLA Lab.

  11. Indexed Sequential Files : Insertion • (Step 1) Locate data level node via key search in which to insert record • (Step 2) Determine if record is to be inserted into primary block or overflow in order to maintain primary key order sequence of records • (Step 3a) If record is to be placed in primary block and block is not full, shift all records with higher-valued primary keys to the right and place new record into vacated slot. STOP. SNU-OOPSLA Lab.

  12. Indexed Sequential Files : Insertion(2) • (Step 3b) If record is to be placed in primary block and block is full, place record of the block with highest valued primary key so that it is the first record on the overflow chain (move one record to the overflow chain) . Primary block is now not full. Go to Step 3a. • (Step 4) If record is to be placed in overflow chain, place record in appropriate position on overflow chain so that primary key sequencing is maintained. STOP. SNU-OOPSLA Lab.

  13. 120 150 insert i A D Yields(step 3a) 130 120 130 150 insert E A E D insert 180 120 130 150 180 Yields(step 4) C A E D C 110 110 120 130 150 180 insert Yields(step 3b) F F A E D C 170 insert 110 120 130 150 170 180 Yields(step 4) G F A E D G C Example : Insertion SNU-OOPSLA Lab.

  14. Indexed Sequential Files : Deletion • (Step 1) Locate record to delete by primary key search • (Step 2) If record is in primary block, free its slot and shift all records in the block with higher-valued primary keys to the left. STOP • (Step 3) If record is in overflow, remove it from overflow chain. STOP SNU-OOPSLA Lab.

  15. 120 110 130 150 170 180 remove yields A F E D G C 150 110 130 170 180 remove yields D F E G C Example : Deletion SNU-OOPSLA Lab.

  16. Indexed Sequential Files : Update • (Step 1) Locate record to update by primary key search • (Step 2) If primary key was not altered, simply replace stored copy of record with the updated copy. STOP. • (Step 3) If primary keywas altered, delete(remove) the located record. Insert updated record just as if were a new record. STOP. SNU-OOPSLA Lab.

  17. Indexed Sequential Files : Reorganization • Reading records out of old file in the primary key order • Building new indexed sequential structure with no records in overflow. (file creation) • Reorganization is really hectic !!! • Definitions • Loading Factor = average number of records per node • Initial Loading Factor = Loading Factor when file is created SNU-OOPSLA Lab.

  18. main memory secondary memory 45 • 70 3 11 30 45 120 1 3 10 11 20 30 40 45 10 120 150 A B A C D D C A C A D 51 57 61 70 50 51 55 57 60 61 45 65 70 D A D B B A E B Example : Reorganization SNU-OOPSLA Lab.

  19. Indexed Sequential Files : Creation • (Step 1) Using a specified initial loading factor LF, pack LF records per node and create the data level of the new indexed sequential file structure. (Last node on data level will have from 1 to LF records in it) • (Step 2) Build consecutive levels of index nodes until a level is reached where there is only a single node. The root node is created and is placed on the next higher level blocks of index are to be packed as full as possible. Stop. SNU-OOPSLA Lab.

  20. 10.2 Maintaining a Sequence Set 10.2 Maintaining a Sequence Set • A sequence set (similar terms: ordered file, sequential set) • a set of records in physical order by key • Sequence set + Simple Index ===> Simple Prefix B+ Tree • The Use of Blocks • We want to rule out sorting and resorting of the sequence set • insertion of records into block : overflow -> split • deletion of records : underflow -> redistribution, concatenation • costs for avoidance of sorting • more space overhead (internal fragmentation in a block) • -> redistribution in place of splitting, two-to-three splitting • the maximum guaranteed extent of physical sequentiality is within a block -> choice of block size SNU-OOPSLA Lab.

  21. 10.2 Maintaining a Sequence Set Block splitting & concatenation(1) Block1 ADAMS...BAIRD...BIXBY...BOONE... Block2 BYNUM...CARSON...COLE...DAVIS... Block3 DENVER...ELLIS... (a)Initial blocked sequence set Block1 ADAMS...BAIRD...BIXBY...BOONE... Block2 BYNUM...CARSON...CARTER... Block3 DENVER...ELLIS... Block4 COLE...DAVIS... (b)Sequence set after insertion of CARTER record - block 2 splits, and the contents are divided between blocks 2 and 4 SNU-OOPSLA Lab. (continued....)

  22. 10.2 Maintaining a Sequence Set Block splitting & concatenation(2) Block1 ADAMS...BAIRD...BIXBY...BOONE... Block2 BYNUM...CARSON...CARTER... Block3 Available for use Block4 COLE...DENVER...ELLIS... (c)Sequence set after deletion of DAVIS record - block 4 is less than half full, so it is concatenated with block3 SNU-OOPSLA Lab.

  23. 10.2 Maintaining a Sequence Set Issue: Choice of Block Size • Block : basic unit for I/O • The maximum guaranteed extent of physical sequentiality • Two considerations • several blocks should be in RAM at once • e.g. for split or concatenation, at least two blocks in RAM • reading/writing a block should not be very long • Cluster :- the minimum number of sectors allocated at a time - the minimum size of a file • Reasonable suggestion: block size == cluster size • can access a block without seeking within a cluster SNU-OOPSLA Lab.

  24. 10.3 Adding a Simple Index to the Sequence Set(1) • An efficient way to locate some specific block containing a particular record, given the record’s key • build index records containing the key for the last record in a block • Possible Index Structures • simple index • binary search of the index • works well while the entire index is in RAM • B+ tree • B-tree index + a sequence set with actual records SNU-OOPSLA Lab.

  25. Sequence of blocks ADAMS -BERNE BOLEN -CAGE CAMP -DUTTON EMBRY -EVANS FABER -FOLK FOLKS -GADDIS 1 2 3 4 5 6 Simple index Key Block Number BERNE CAGE DUTTON EVANS FOLK GADDIS 1 2 3 4 5 6 SNU-OOPSLA Lab.

  26. 10.4 The Content of the Index :Separators Instead of Keys • Need not to have actual keys in the index set • Our real need is separators • Separator - distinguishes between 2 blocks • among many candidates, shortest separator is preferable • there is not always a unique shortest separator SNU-OOPSLA Lab.

  27. Separators between blocks in the sequence set Separators: BO CAM E F FOLKS ADAMS -BERNE BOLEN -CAGE CAMP -DUTTON EMBRY -EVANS FABER -FOLK FOLKS -GADDIS 1 2 3 4 5 6 A list of potential separators DUTU DVXGHSJF DZ E EBQX ELEEMOSYNARY CAMP -DUTTON EMBRY -EVANS SNU-OOPSLA Lab.

  28. 10.5 The Simple Prefix B+ Tree • Index like B-tree + blocks of sequential sets • The use of simple prefixes • prefixes of the keys rather than actual keys • contains shortest separators • N separators -> N+1 children • Properties of B+ tree • B-tree like Index • Sequential data set • Indexed-sequential file SNU-OOPSLA Lab.

  29. E Index set BO CAM F FOLKS ADAMS -BERNE BOLEN -CAGE CAMP -DUTTON EMBRY -EVANS FABER -FOLK FOLKS -GADDIS 1 2 3 4 5 6 A B-tree index set for the sequence set, forming a simple prefix B+ tree SNU-OOPSLA Lab.

  30. 10.6 Simple Prefix B+ Tree Maintenance (1) • Changes localized to single blocks in the sequence set • deletion without concatenation, redistribution • e.g. delete EMBRY, FOLKS • insertion without splitting • e.g. insert EATON SNU-OOPSLA Lab.

  31. Deletion of the EMBRY and FOLKS from the sequence set E BO CAM F FOLKS ADAMS -BERNE BOLEN -CAGE CAMP -DUTTON ERVIN -EVANS FABER -FOLK FROST -GADDIS 1 2 3 4 5 6 SNU-OOPSLA Lab.

  32. 10.6 Simple Prefix B+ Tree Maintenance(2) • Changes involving multiple blocks in the sequence set • split, concatenation : propagate to index set • change the number of blocks in the sequence set • change the number of separators • change the index set • insertion with splitting • e.g. overflow in block1 • block1, block7 with separator AY • deletion with concatenation/redistribution • e.g. underflow in block2 block2, block3 split concatenation SNU-OOPSLA Lab.

  33. An insertion into block 1 causes a split and the consequent addition of block 7 BO E AY CAM F FOLKS ADAMS -AVERY AYERS -BERNE BOLEN -CAGE CAMP -DUTTON ERVIN -EVANS FABER -FOLK FROST -GADDIS 1 7 2 3 4 5 6 SNU-OOPSLA Lab.

  34. A deletion from block 2 causes underflow and the consequent concatenation of blocks 2 and 3 E AY BO F FOLKS ADAMS -AVERY AYERS -BERNE BOLEN -DUTTON ERVIN -EVANS FABER -FOLK FROST -GADDIS 1 7 2 4 5 6 SNU-OOPSLA Lab.

  35. Bottom up procedure to handle changes ** insert/delete in the sequence set as if there is no B-tree index set if blocks are split a new separator must be inserted into the index set if blocks are concatenated a separator must be removed from the index set if records are redistributed between blocks the value of a separator in the index set must be changed else no propagation to index set SNU-OOPSLA Lab.

  36. 10.7 Index Set Block Size • size of an index node for the index set • == size of a data block in the sequence set • Reasons for using a common block size • the best size for sequence set is usually the best for the index set • a common block size makes it easier to implement a buffering scheme • the index set blocks and sequence set blocks are often mingled within the same file • to avoid seeking between separate files while accessing the simple prefix B+ tree SNU-OOPSLA Lab.

  37. 10.8 Internal Structure of Index Set Blocks: A variable-order B-tree • Variable-length shortest separator • possibility of packing them into a node • separator index (fixed length) : means of performing binary searches on a list of variable-length entities • A simple prefix B+ tree with a variable order • not maximum order -> not minimum depth • decisions about when to split, concatenate, or redistribute become more complicated SNU-OOPSLA Lab.

  38. separators As, Ba, Bro, C, Ch, Cra, Dele, Edi, Err, Fa, File AsBaBroCChCraDeleEdiErrFaFile 00 02 04 07 08 10 13 17 20 23 25 Variable-length separators and corresponding index Separator count Total length of separators 11 28 AsBaBroCChCraDeleEdiErrFaFile 00 02 04 07 08 10 13 17 20 23 25 B00 B01 ..... B10 B11 Relative block numbers Separators Index to separators Structure of an index set block SNU-OOPSLA Lab.

  39. 10.9 Loading a Simple Prefix B+ Tree(1) • One way is successive insertions and splits • The other way is using separate loading process • working from a sorted file and then • place the records into sequence set block • if one block is full • determine the separator and insert it into the index set block • place the records into new sequence set block SNU-OOPSLA Lab.

  40. 10.9 Loading Simple Prefix B+ Tree(2) • Advantages to using a separate loading process • the output can be written sequentially • simple than succcessive insert & split • performance during loading • can load 100% utilization (c.f. insert & split produces blocks between 67~80% full) • creating a degree of spatial locality SNU-OOPSLA Lab.

  41. 10.10 B+ Trees • Contains copies of actual keys • cf. simple prefix B+ tree : separator ALWAYS/ASPECT/BETTER 00 06 12 Next separator: CATCH Next sequence set block: ACCESS -ALSO ALWAYS -ASK ASPECT -BEST BETTER -CAST CATCH -CHECK SNU-OOPSLA Lab.

  42. 10.11 B-Tree, B+ Tree and Simple Prefix B+Tree in Perspective • Shared characteristics • Paged index structures : broad and shallow • Height-balanced • Growing from bottom-up • Possible to obtain greater storage efficiency through two-three block splitting, concatenation, redistribution • Can be implemented as virtual tree structures • Can be adapted for variable-length records SNU-OOPSLA Lab.

  43. B-Trees • General Characteristics • Information can be found at any level of the B-tree • B-tree take up less space than B+ tree (B+ tree  has additional space) • Ordered sequential access • Through in-order traversal of the tree(virtual tree is necessary) • Separated record files(B-tree has only pointers) are not workable SNU-OOPSLA Lab.

  44. B+Trees • General Characteristics • Separation of index set and sequence set • Separators : copies of keys • Shallower tree than B-tree • Ordered sequential access • Sequence set is truly linear • efficient access to records in order by key SNU-OOPSLA Lab.

  45. Simple Prefix B+ Trees • General Characteristics • Separators : smaller than actual keys • Shallower than B+ Trees • Separator compression, variable-length field management overhead • Ordered sequential access • Sequence set is truly linear (same as B+ Tree) SNU-OOPSLA Lab.

  46. Let’s Review !!! • 10.1 Indexed Sequential Access • 10.2 Maintaining a Sequence Set • 10.3 Adding a Simple Index to the Sequence Set • 10.5 The Contents of the Index: Separators Instead of Keys • 10.6 The Simple Prefix B+ Tree Maintenance • 10.7 Index Set Block size • 10.8 Internal Structure of the Index Set Blocks: A variable-order B-Tree • 10.9 Loading a Simple Prefix B+ Tree • 10.10 B+ Trees • 10.11 B-Trees, B+ Trees, and Simple Prefix B+ Trees in Perspective SNU-OOPSLA Lab.

More Related