Tallahassee, Florida, 2016 COP5725 Advanced Database Systems Storage and Representation Spring 2016.

Slides:



Advertisements
Similar presentations
Physical DataBase Design
Advertisements

CS 245Notes 31 (1) Insertion/Deletion (2) Buffer Management (3) Comparison of Schemes Other Topics.
Dr. Kalpakis CMSC 661, Principles of Database Systems Representing Data Elements [12]
1 Introduction to Database Systems CSE 444 Lectures 19: Data Storage and Indexes November 14, 2007.
File Organizations Sept. 2012Yangjun Chen ACS-3902/31 Outline: File Organization Hardware Description of Disk Devices Buffering of Blocks File Records.
1 Storing Data: Disks and Files Yanlei Diao UMass Amherst Feb 15, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Database Implementation Issues CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 5 Slides adapted from those used by Jennifer Welch.
CS 4432lecture #61 CS4432: Database Systems II Lecture #6 Professor Elke A. Rundensteiner.
Recap of Feb 27: Disk-Block Access and Buffer Management Major concepts in Disk-Block Access covered: –Disk-arm Scheduling –Non-volatile write buffers.
SECTIONS 13.1 – 13.3 Sanuja Dabade & Eilbroun Benjamin CS 257 – Dr. TY Lin SECONDARY STORAGE MANAGEMENT.
Data Storage and Access Methods Min Song IS698. Database Design Process Conceptual Model Logical Model External Model Conceptual requirements Conceptual.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 13 Disk Storage, Basic File Structures, and Hashing.
Physical Storage Organization. Advanced DatabasesPhysical Storage Organization2 Outline Where and How data are stored? –physical level –logical level.
CS 255: Database System Principles slides: Variable length data and record By:- Arunesh Joshi( 107) Id: Cs257_107_ch13_13.7.
SECTIONS 13.1 – 13.3 Sanuja Dabade & Eilbroun Benjamin CS 257 – Dr. TY Lin SECONDARY STORAGE MANAGEMENT.
DBMS Internals: Storage February 27th, Representing Data Elements Relational database elements: A tuple is represented as a record CREATE TABLE.
DISK STORAGE INDEX STRUCTURES FOR FILES Lecture 12.
Secondary Storage Management Hank Levy. 8/7/20152 Secondary Storage • Secondary Storage is usually: –anything outside of “primary memory” –storage that.
Introduction to Database Systems 1 The Storage Hierarchy and Magnetic Disks Storage Technology: Topic 1.
Layers of a DBMS Query optimization Execution engine Files and access methods Buffer management Disk space management Query Processor Query execution plan.
CS4432: Database Systems II Data Storage (Better Block Organization) 1.
CHP - 9 File Structures. INTRODUCTION In some of the previous chapters, we have discussed representations of and operations on data structures. These.
Lecture 11: DMBS Internals
Physical Storage Organization. Advanced DatabasesPhysical Storage Organization2 Outline Where and How are data stored? –physical level –logical level.
Chapter 10 Storage and File Structure Yonsei University 2 nd Semester, 2013 Sanghyun Park.
13.6 Representing Block and Record Addresses
CMPT 454, Simon Fraser University, Fall 2009, Martin Ester 75 Database Systems II Record Organization.
Chapter 121 Chapter 12: Representing Data Elements (Slides by Hector Garcia-Molina,
Chapter 3 Representing Data Elements 1.How to lay out data on disk 2.How to move it to memory.
OSes: 11. FS Impl. 1 Operating Systems v Objectives –discuss file storage and access on secondary storage (a hard disk) Certificate Program in Software.
Database Management Systems,Shri Prasad Sawant. 1 Storing Data: Disks and Files Unit 1 Mr.Prasad Sawant.
External Storage Primary Storage : Main Memory (RAM). Secondary Storage: Peripheral Devices –Disk Drives –Tape Drives Secondary storage is CHEAP. Secondary.
CS4432: Database Systems II Record Representation 1.
Physical Storage Organization. Advanced DatabasesPhysical Storage Organization2 Outline Where and How data are stored? –physical level –logical level.
1 CS 232A: Database System Principles Notes 03: Disk Organization.
DMBS Internals I. What Should a DBMS Do? Store large amounts of data Process queries efficiently Allow multiple users to access the database concurrently.
File Structures. 2 Chapter - Objectives Disk Storage Devices Files of Records Operations on Files Unordered Files Ordered Files Hashed Files Dynamic and.
DMBS Internals I February 24 th, What Should a DBMS Do? Store large amounts of data Process queries efficiently Allow multiple users to access the.
DMBS Internals I. What Should a DBMS Do? Store large amounts of data Process queries efficiently Allow multiple users to access the database concurrently.
Representing Block & Record Addresses
CS411 Database Systems Kazuhiro Minami 09: Storage.
Chapter 5 Record Storage and Primary File Organizations
CS4432: Database Systems II
Data Storage COMP3017 Advanced Databases Dr Nicholas Gibbins
1 Lecture 16: Data Storage Wednesday, November 6, 2006.
Chapter 31 Chapter 3 Representing Data Elements. Chapter 32 Fields, Records, Blocks, Files Fields (attributes) need to be represented by fixed- or variable-length.
Query Processing Part 1: Managing Disks 1.
Module 11: File Structure
Lecture 16: Data Storage Wednesday, November 6, 2006.
9/12/2018.
CS 245: Database System Principles Notes 03: Disk Organization
Lecture 11: DMBS Internals
Sanuja Dabade & Eilbroun Benjamin CS 257 – Dr. TY Lin
Disk Storage, Basic File Structures, and Buffer Management
Database Implementation Issues
Lecture 15: Midterm Review Data Storage
Lecture 19: Data Storage and Indexes
Representing Block & Record Addresses
Secondary Storage Management Brian Bershad
CS 245: Database System Principles Disk Organization
DATABASE IMPLEMENTATION ISSUES
CSE 544: Lecture 11 Storing Data, Indexes
Introduction to Database Systems CSE 444 Lectures 19: Data Storage and Indexes May 16, 2008.
Secondary Storage Management Hank Levy
Database Implementation Issues
Lecture 15: Data Storage Tuesday, February 20, 2001.
Database Implementation Issues
Lecture 20: Representing Data Elements
Database Implementation Issues
Presentation transcript:

Tallahassee, Florida, 2016 COP5725 Advanced Database Systems Storage and Representation Spring 2016

Memory Hierarchy 1 Registers Level one Cache Level two Cache Main memory Hard disk Tertiary storage Increasing cost and speed Decreasing size Decreasing cost and speed, Increasing size

Why Memory Hierarchy Three questions asked when creating memory: – How fast – How much – How expensive The purpose of the hierarchy is to allow fast access to large amounts of memory at a reasonable cost 2

Memory Hierarchy Cache (volatile) – Size: in megabytes (10 6 bytes) – Speed: between cache and processor: a few nanoseconds (10 -9 seconds) Main Memory (volatile) – Size: in gigabytes (10 9 bytes) – Speed: between memory and cache: nanoseconds Secondary Storage (nonvolatile) – Size: in terabytes (10 12 bytes) – Speed: between disk and main memory: 10 milliseconds (10 -3 seconds) Tertiary Storage (nonvolatile) – Magnetic tapes, optical disks, …… – Size: in terabytes (10 12 bytes) or petabytes (10 15 bytes) – Speed: between tertiary storage and disks: seconds or minutes 3

Virtual Memory Virtual memory is not really physical memory! – Is NOT a level of the memory hierarchy – It is a technique that gives programs the idea that it has working memory even if physically it may overflow to disk storage – OS manages virtual memory It makes programming large applications easier and efficiently uses real physical memory 4

Second Storage Disk – Slower, cheaper than main memory – Persistent !!! – The unit of disk I/O = block Typically 1 block = 4k – Mechanical characteristics: Rotation speed (7200RPM) Number of platters (1-30) Number of tracks (<=10000) Number of bytes/track(10 5 ) –

Disk Access Characteristics Disk latency – Time between when command is issued and when data is in memory – = seek time + rotational latency + transfer time Seek time = time for the head to reach cylinder: 10ms – 40ms Rotational latency = time for the sector to rotate – rotation time = 10ms Transfer time = typically 5-10MB/s – Disks read/write one block at a time (typically 4kB) 6

I/O Model of Computation Dominance of I/O cost – The time taken to perform a disk access is much larger than the time for manipulating data in main memory – The number of block accesses (disk I/O’s) is a good approximation to the time of an algorithm and should be minimized – Throughput: # disk accesses per second the system can accommodate Accelerating Access to Hard Disks – Place data blocks on the same cylinder – Divide the data among several smaller disks – Mirror a disk – Disk scheduling algorithms – Prefetch blocks to main memory in anticipation of their later use 7

I/O Model of Computation Rule of Thumb – Random I/O: Expensive; sequential I/O: much less – Example: 1 KB Block Random I/O:  10 ms Sequential I/O:  <1 ms Cost for write similar to read To Modify Block 1.Read Block 2.Modify in Memory 3.Write Block 4.(optional) Verify 8

The Elevator Algorithm Question – For the disk controller, which of several block requests to execute first? Assumption – Requests are from independent processes and have no dependencies Algorithm: 1.As heads pass a cylinder, stop to process block read/write requests on the cylinder 2.Heads proceed in the same direction until the next cylinder with blocks to access is encountered 3.When heads found there are no requests ahead in the direction of travel, reverse direction 9

Single Buffering vs. Double Buffering Problem: Have a file with a sequence of blocks B1, B2, …… have a program, process B1, B2, …… Single Buffer Solution – Read B1  Buffer; process data in buffer; read B2  buffer; process data in buffer... – P = time to process/block; R = time to read in 1 block; n = # blocks: Single buffer time = n(P+R) Double Buffer Solution – Double buffering time = R + nP if P >=R 10

Double Buffering 11 ABCDGEFA B done process A C B done

Representing Data Elements Terminology in Secondary Storage Example: CREATE TABLE Product ( pid INT PRIMARY KEY, name CHAR(20), description VARCHAR(200), maker CHAR(10) REFERENCES Company(name) ) 12 Data ElementRecordCollection DBMSAttributeTupleRelation File SystemFieldRecordFile

Representing Data Elements What we have available: Bytes (8 bits) (Short) Integer : 2 bytes – e.g., 35 is Real, floating point – n bits for mantissa, m for exponent – e.g., is 12345*10 -4 Characters – various coding schemes suggested, most popular is ASCII – e.g., A: ; a: Boolean – True: ; false:

Representing Data Elements 14 Dates – e.g.: integer, # days since Jan 1, 1900 or 8 characters, YYYYMMDD Time – e.g. : integer, seconds since midnight or characters HHMMSS String of characters – Null terminated – Length given – Fixed length ctacta 3

Record Formats: Fixed Length Information about field types is same for all records in a file – stored in system catalogs – Finding i’th field requires scan of record Record Header 1.Pointer to the schema: find the fields of the record 2.Length: skip over records without consulting the schema 3.Timestamps: the record last modified or read 15

Variable Length Records Example: – Place the fixed fields first: F1, F2 – Then the variable-length fields: F3, F4 Pointers to the beginning of all the variable-length fields – Null values take 2 bytes only sometimes they take 0 bytes (when at the end) 16

Records With Repeating Fields A record contains a variable number of occurrences of a field, but the field itself is of fixed length – e.g., An employee has one or more children – Group all occurrences of the field together and put in the record header a pointer to the first 17

Placing Records into Blocks 18 blocks... a file assume fixed length blocks assume a single file

Storing Records in Blocks Blocks have fixed size (typically 4k) and record sizes are smaller than block sizes 19

Spanned vs. Unspanned Unspanned: records must be within one block – much simpler, but may waste space… block 1 block 2... Spanned – When records are very large (record size > block size) – Or even medium size: saves space in blocks block 1 block R1R2R3R4R5 R1R2 R3 (a) R3 (b) R6R5R4 R7 (a) need indication of partial record “pointer” to rest need indication of continuation (+ from where?)

Sequencing Ordering records in file (and block) by some key value Why? – Typically to make it possible to efficiently read records in order – e.g., to do a merge-join — discussed later Options: – Next record physically contiguous – Linked 21 Next (R1)R1 Next (R1)

BLOB Binary large objects – Supported by modern database systems E.g. images, sounds, etc. Storage – attempt to cluster blocks together and store them on a sequence of blocks 1.On a cylinder or cylinders of the disk 2.On a linked list of blocks 3.Stripe (alternate blocks of) BLOB across several disks, such that several blocks of the BLOB can be retrieved simultaneously 22

Database Addresses Physical Address: Each block and each record have a physical address that consists of – The host – The disk – The cylinder number – The track number – The block within the track – For records: an offset in the block, sometimes this is in the block’s header Logical Addresses: Record ID is arbitrary bit string – More flexible – But need translation table 23

Addresses 24 Header A block:Free space R3 R4 R1R2

Memory Addresses Main Memory Address – When the block is read in main memory, it receives a main memory address 25

Pointer Swizzling The process of replacing a physical/logical pointer with a main memory pointer – need translation table such that subsequent references are faster Idea: – When we move a block from secondary to main memory, pointers within the block may be “swizzled” – Translation from the DB address to memory address 26

Pointer Swizzling Automatic Swizzling (Eager) – when block is read in main memory, swizzle all pointers in the block On demand – Leave all pointers unswizzled when the block is first brought into memory, and swizzle only when user requests No swizzling (Lazy) – always use translation table – the pointers are followed in their unswizzled form – The records cannot be pinned in memory 27

Pointer Swizzling When blocks return to disk – pointers need unswizzled Danger: someone else may point to this block – Pinned blocks: we don’t allow it to return to disk – Keep a list of references to this block 28

Record Modification: Insertion File is unsorted (= heap file) – add it to the end (easy !) File is sorted – Is there space in the right block ? Yes: we are lucky, store it there – Is there space in a neighboring block ? Look 1-2 blocks to the left/right, shift records – If anything else fails, create overflow block 29

Record Modification: Deletion Free space in block, shift records – Maybe be able to eliminate an overflow block Can never really eliminate the record, because others may point to it – Place a tombstone instead (a NULL record) 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,... 30

Record Modification: Update If new record is shorter than previous, easy ! If it is longer, need to shift records, create overflow blocks 31

Row Store 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) 32

Row Store vs. Column Store Advantages of Column Store – more compact storage (fields need not start at byte boundaries) – efficient reads on data mining and OLAP operations Advantages of Row Store – writes (multiple fields of one record) more efficiently – efficient reads for record access (OLTP)

Summary There are 10,000,000 ways to organize my data on disk – Which is right for me? Issues: FlexibilitySpace Utilization ComplexityPerformance 34