Download presentation
Presentation is loading. Please wait.
Published byFlorence Morrison Modified over 9 years ago
1
CS 4432lecture #51 Data Items Records Blocks Files Memory Next:
2
CS 4432lecture #52 Goal : placing records into blocks blocks... a file assume fixed length blocks assume a single file (for now) records
3
CS 4432lecture #53 (1) separating records (2) spanned vs. unspanned (3) mixed record types – clustering (4) split records (5) sequencing (6) indirection Options for storing records in blocks:
4
CS 4432lecture #54 Block (a) no need to separate if fixed size records. (b) or, use special marker (c) or, give record lengths (or offsets) - within each record - in block header (1) Separating records R2R1R3
5
CS 4432lecture #55 Unspanned: records within one block block 1 block 2... Spanned : records wrap across 2 blocks block 1 block 2... (2) Spanned vs. Unspanned R1R2 R1 R3R4R5 R2 R3 (a) R3 (b) R6R5R4 R7 (a)
6
CS 4432lecture #56 Unspanned is much simpler, but may sometimes waste space… Spanned essential if record size > block size Spanned vs. unspanned:
7
CS 4432lecture #57 Example 10 6 records each of size 2,050 bytes (fixed) block size = 4096 bytes block 1 block 2 2050 bytes wasted 2046 2050 bytes wasted 2046 R1R2 Utiliz = 50% -> ½ of space is wasted
8
CS 4432lecture #58 Mixed - records of different types (e.g., EMPLOYEE, DEPT) allowed in same block e.g., a block (3) Mixed versus uniform record types EMP e1 DEPT d1 DEPT d2
9
CS 4432lecture #59 Why do we want to mix? Answer: CLUSTERING Records that are frequently accessed together should be placed into the same block
10
CS 4432lecture #510 Example Clustering Q1: select C_NAME, C_CITY, AMOUNT, … from DEPOSIT, CUSTOMER where DEPOSIT.C_NAME = CUSTOMER.C.NAME a block layout: CUSTOMER,NAME=SMITH DEPOSIT,NAME=SMITH CUSTOMER,NAME=JONES Question: Good idea or bad idea ?
11
CS 4432lecture #511 If Q1 frequent with join on customer and deposit relations, then clustering good But if instead Q2 frequent with : Q2: SELECT * FROM CUSTOMER then clustering is counter-productive
12
CS 4432lecture #512 Mixing of record types on one block? Problems: Creates variable length records in block May cause us to store duplicates Insert/deletes are harder
13
CS 4432lecture #513 Other Ideas ? Compromise: No mixing, but keep related records in same cylinder...
14
CS 4432lecture #514 (1) Separating records (2) Spanned vs. Unspanned (3) Mixed record types - Clustering (4) Split records (5) Sequencing (6) Indirection Recap: Storing records in blocks
15
CS 4432lecture #515 (1) separating records (2) spanned vs. unspanned (3) mixed record types – clustering (4) split records (5) sequencing (6) indirection Options for storing records in blocks:
16
CS 4432lecture #516 Fixed part in one block Typically for hybrid format Variable part in another block (4) Split records
17
CS 4432lecture #517 Block with fixed recs. R1 (a) R1 (b) Block with variable recs. R2 (a) R2 (b) R2 (c)
18
CS 4432lecture #518 Ordering records in file (and thus blocks) by some key value –Sequential file ( sequenced file ) Why sequencing ? –Typically maked it possible to efficiently read records in order (5) Sequencing
19
CS 4432lecture #519 Sequencing Options (a) Next record physically contiguous... (b) Linked What about INSERT/ DELETE ? Next (R1)R1 Next (R1)
20
CS 4432lecture #520 (c)Overflow area Records in sequence R1 R2 R3 R4 R5 Sequencing Options header R2.1 R1.3 R4.7
21
CS 4432lecture #521 How does one refer to records? Problem: Records can be on disk or in (virtual) memory. Need common address, but have different physical locations. (6) Indirection Addressing Rx Many options: PhysicalIndirect
22
CS 4432lecture #522 Purely Physical Addressing Device ID E.g., RecordCylinder # Address=Track # ( ID ) Block # Offset in block Block ID
23
CS 4432lecture #523 Fully Indirect Addressing Solution: Record ID (Oracle: ROWID) as global address, maintain a map table. Map Table rec ID raddress a Physical addr. Rec ID
24
CS 4432lecture #524 Tradeoff Flexibility Cost to move recordsof indirection (for deletions, insertions) (lookup) What to do : Options inbetween ? Physical Indirect
25
CS 4432lecture #525 Ex #1 : Indirection in block Block Header A block:Free space R3 R4 R1R2
26
CS 4432lecture #526 Block header - data at beginning that describes block May contain: - File ID (or RELATION or DB ID) - This block ID - Record directory - Pointer to free space - Type of block (e.g. contains recs type 4; is overflow, …) - Pointer to other blocks “like it” - Timestamp...
27
CS 4432lecture #527 Ex. #2 Use logical block #’s understood by file system instead of direct disk access REC ID File ID Block # Record # or Offset File ID,Physical Block #Block ID File System Map
28
CS 4432lecture #528 (1) Separating records (2) Spanned vs. Unspanned (3) Mixed record types - Clustering (4) Split records (5) Sequencing (6) Indirection Recap: Storing records in blocks
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.