29
Storage and File Organization Wherein we start looking inside the database

Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

  • Upload
    others

  • View
    6

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Storage and File Organization

Wherein we start looking inside the database

Page 2: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Application

Logical Data Model

Physical Implementation

SQL

Query Plan

JSON

Materialized Results

Correctness

Performance

Page 3: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

PerformanceMemory Hierarchy

Access Patterns

Page 4: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

https://en.wikipedia.org/wiki/Memory_hierarchy#/media/File:ComputerMemoryHierarchy.svg

Page 5: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

http://csappbook.blogspot.com/2017/05/a-gallery-of-memory-mountains.html

Page 6: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Storing and Organizing Fixed Length Tuples

Page 7: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Delete record 3

Page 8: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space
Page 9: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Wasted Space

Page 10: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Storing and Organizing Variable Length Tuples

Page 11: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Fixed Size

4 fields, 0 = not null, 1 = null

Page 12: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Access one block at a time - typically

4096 bytes

Page 13: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Database File … …

Page 14: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Order of tuples in a file: Sequential Order

Page 15: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Can easily find key

Page 16: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Order of tuples in a file: Multitable Clustering

Page 17: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space
Page 18: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Order of tuples in a file: Heap File

Page 19: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Database File … …

Array of 3-bit values (maximum value = 8)

6/8 = 75%

Has space? Insert!

Page 20: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Storing Metadata? Use what you have! Relations!

Page 21: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space
Page 22: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

https://en.wikipedia.org/wiki/Memory_hierarchy#/media/File:ComputerMemoryHierarchy.svg

Computation Happens Here

Page 23: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Buffer Management

Page 24: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Buffer

Database File … …

RAMDisk

read(Database File, Block n)read(Database File, Block m)

Operation 1 accesses block

pin!

1

Operation 2 accesses block

pin!

2

read(Database File, Block x)

…Full!

Page 25: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

A Modern Alternative

Page 26: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

10101 Srinavasan Comp. Sci. 65000

1212 Wu Finance 90000

15151 Mozart Music 40000

10101 Srinavasan Comp. Sci. 65000

1212 Wu Finance 90000

15151 Mozart Music 40000

Row Storage Column Storage

Inserts and deletes for each tuple are fast Scans on a single attribute are slow

Scan on a few attributes are fast Compression CPU cache performance

Need to reconstruct the tuple Decompression cost Inserting a tuple is random access

Page 27: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

On disc:

• ORC or Parquet Format • Popular for BIG DATA and

Distributed Settings

Partition of the relation

Page 28: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

In main memory:

• No buffer manager • Possible due to: • heavy compression • larger (TBs) main memory

Partition of the relation

Page 29: Storage and File Organization - cs.brown.edu · Storage and File Organization Wherein we start looking inside the database. ... Fixed Length Tuples. Delete record 3. Wasted Space

Questions?