cs 245notes 31 (1) insertion/deletion (2) buffer management (3) comparison of schemes other topics

25
CS 245 Notes 3 1 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

Upload: mackenzie-marrin

Post on 14-Dec-2015

220 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 1

(1) Insertion/Deletion(2) Buffer Management(3) Comparison of Schemes

Other Topics

Page 2: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 2

Block

Deletion

Rx

Page 3: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 3

Options:

(a) Immediately reclaim space(b) Mark deleted

Page 4: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 4

Options:

(a) Immediately reclaim space(b) Mark deleted

– May need chain of deleted records

(for re-use)– Need a way to mark:

• special characters• delete field• in map

Page 5: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 5

As usual, many tradeoffs...

• How expensive is to move valid record to free space for immediate reclaim?

• How much space is wasted?– e.g., deleted records, delete fields,

free space chains,...

Page 6: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 6

Dangling pointers

Concern with deletions

R1 ?

Page 7: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 7

Solution #1: Do not worry

Page 8: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 8

E.g., Leave “MARK” in map or old location

Solution #2: Tombstones

Page 9: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 9

E.g., Leave “MARK” in map or old location

Solution #2: Tombstones

• Physical IDs

A block

This space This space cannever re-used be re-used

Page 10: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 10

• Logical IDs

ID LOC

7788

map

Never reuseID 7788 nor

space in map...

E.g., Leave “MARK” in map or old location

Solution #2: Tombstones

Page 11: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 11

Easy case: records not in sequence Insert new record at end of

file or in deleted slot If records are variable size,

not as easy...

Insert

Page 12: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 12

Hard case: records in sequence If free space “close by”, not too bad... Or use overflow idea...

Insert

Page 13: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 13

Interesting problems:

• How much free space to leave in each block, track, cylinder?

• How often do I reorganize file + overflow?

Page 14: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 14

Freespace

Page 15: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 15

• DB features needed• Policies – LRU bad? • Pinned blocks• Forced output• Double buffering• Swizzling

Buffer Management

in prior notes

Page 16: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 16

Swizzling

Memory Disk

Rec A

block 1

block 2

block 1

Page 17: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 17

Swizzling

Memory Disk

Rec A

block 1

Rec Ablock 2 block 2

block 1

Page 18: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 18

Row vs Column Store

• So far we assumed that fields of a record are stored contiguously (row store)...

• Another option is to store “like fields” together (column store)

Page 19: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 19

• Example: Order table has schema :– id, cust, prod, store, price, date, qty

Row Store

id1 cust1 prod1 store1 price1 date1 qty1

id2 cust2 prod2 store2 price2 date2 qty2

id3 cust3 prod3 store3 price3 date3 qty3

Page 20: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 20

• Example: Order consists of– id, cust, prod, store, price, date, qty

Column Store

id1 cust1id2 cust2id3 cust3id4 cust4... ...

id1 prod1id2 prod2id3 prod3id4 prod4... ...

id1 price1 qty1id2 price2 qty2id3 price3 qty3id4 price4 qty4... ... ...

ids may or may not be stored explicitly

Page 21: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 21

Row vs Column Store

• Advantages of Column Store– more compact storage (fields not at byte

boundary)– replication/compression– efficient reads on data analytics/mining (OLAP)

• Advantages of Row Store– writes (multiple fields of one record) more

efficient– efficient reads for record access (OLTP)

Page 22: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 22

Literature :

• Mike Stonebreaker, Elizabeth O'Neil, Pat O’Neil, Xuedong Chen, et al. " C-Store: A Column-oriented DBMS," VLDB Conference, 2005.

• Commerialized as Vertica In (Boston!); also LucidDB, MonetDB, and others.

Page 23: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 23

• There are 10,000,000 ways to organize my data on disk…

Which is right for me?

Comparison

Page 24: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 24

Issues:

Flexibility Space Utilization

Complexity Performance

Page 25: CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics

CS 245 Notes 3 25

To evaluate a given strategy, compute following parameters:-> space used for expected data-> expected time to

- fetch record given key- fetch record with next key- insert record- append record- delete record- update record- read all file- reorganize file