โ† Database Technology

Learn / Database Technology

DBT: Storage, Layouts, Caching

Memory hierarchy, storage layouts, caching concepts, and record/page-size calculations.

Learning path

0%

0 of 7 sections marked complete ยท about 43 minutes

Learning objectives

What you will be able to explain

  • Which level of the memory hierarchy can be accessed the fastest?
  • Temporal locality means ...
  • Which level of the memory hierarchy can typically store the most data?
  • RAID 5 improves the protection against data loss caused by crashes.
  • Row stores yield better performance for transactional workloads than column stores.
  • Disk access of analytical queries is reduced when using column stores.

Section 01

Which level of the memory hierarchy can be accessed the fastest? to Which level of the memory hierarchy can typically store the most data?

01

Which level of the memory hierarchy can be accessed the fastest?

The correct answer is: Registers.

Guided checkpoint

Choose one answer.

02

Temporal locality means ...

Only repeated access to the same data item in a short time interval expresses temporal locality.

Guided checkpoint

Mark each statement as True or False.

03

Which level of the memory hierarchy can typically store the most data?

The correct answer is: Tertiary storage.

Guided checkpoint

Choose one answer.

Section 02

RAID 5 improves the protection against data loss caused by crashes. to Disk access of analytical queries is reduced when using column stores.

01

RAID 5 improves the protection against data loss caused by crashes.

Die richtige Antwort ist 'Wahr'.

02

Row stores yield better performance for transactional workloads than column stores.

Die richtige Antwort ist 'Wahr'.

03

Disk access of analytical queries is reduced when using column stores.

Analytical queries usually scan few columns; column layout improves I/O efficiency. Die richtige Antwort ist 'Wahr'.

Section 03

Column stores, in general, yield better performance when doing point queries (e.g., reading a single tuple) compared to row stores. to Vertical partitioning aims at reducing the I/O cost for every single incoming query.

01

Column stores, in general, yield better performance when doing point queries (e.g., reading a single tuple) compared to row stores.

Reconstructing a single tuple in a pure column store is typically slower. Die richtige Antwort ist 'Falsch'.

02

Which of the following statements is true for 'vertical partitioning'?

The correct answer is: data is stored once, with attributes split between row-oriented and column-oriented partitions.

Guided checkpoint

Choose one answer.

03

Vertical partitioning aims at reducing the I/O cost for every single incoming query.

Die richtige Antwort ist 'Falsch'.

Section 04

Pointer swizzling and unswizzling are used to... to How many blocks are retrieved for employee_id = 1?

01

Pointer swizzling and unswizzling are used to...

The correct answer is mapping references between database address space and virtual memory.

Guided checkpoint

Choose one answer.

02

How many blocks are retrieved for AVG(amount)?

Work through the guided checkpoint and explain each step in your own words before moving on.

Guided checkpoint

Consider the following relation R:

employee_idpayment_idamountdate
125012/05/2020
243021/04/2021
332015/07/2020
4610030/06/2020
547511/02/2020
659021/03/2020
7731010/01/2021
8714525/10/2020

Assume:

  • Each field in a record consumes 4 bytes (integers as well as the date).
  • Block size as well as page size is 32 bytes.
  • No extra storage overhead is required for any storage model (i.e., page and block are same sized and contain purely data).
  • For each query in the question below, the disk head is above the first block to be read.
  • No further information about the schema exists (especially no info on indices and constraints).

How many blocks are retrieved from disk for the following query?

SELECT AVG(amount)
FROM R;

03

How many blocks are retrieved for employee_id = 1?

Work through the guided checkpoint and explain each step in your own words before moving on.

Guided checkpoint

Consider the following relation R:

employee_idpayment_idamountdate
125012/05/2020
243021/04/2021
332015/07/2020
4610030/06/2020
547511/02/2020
659021/03/2020
7731010/01/2021
8714525/10/2020

Assume:

  • Each field in a record consumes 4 bytes (integers as well as the date).
  • Block size as well as page size is 32 bytes.
  • No extra storage overhead is required for any storage model (i.e., page and block are same sized and contain purely data).
  • For each query in the question below, the disk head is above the first block to be read.
  • No further information about the schema exists (especially no info on indices and constraints).

How many blocks are retrieved from disk for the following query?

SELECT *
FROM R
WHERE employee_id = 1;

Section 05

How large is one record if memory is 4-byte aligned? to CLOCK (Second Chance): final cache content

01

How large is one record if memory is 4-byte aligned?

4 + 4 + 4 + 28 + 4 + 8 = 52 bytes.

Guided checkpoint

Consider the record structure with header fields pointer2schema, length, timestamp and data fields name, age, state.

NameAgeStatepointer2schemalengthtimestamp
FieldSize (bytes)
pointer2schema1
length1
timestamp1
name28
age2
state6

Note: all fields are aligned separately.

02

How many pages are required if the page size is 256 bytes?

Die richtige Antwort ist: 2. records =[8 + 19, 11 + 16, 12 + 17, 12 + 16, 21 + 17, 16 + 21] record_overhead = 8 + 4 + 2 + 2 + 2 + 2 sum_records = sum(records) + record_overhead * len(records) pages = (sum_records // (256 - 12)) + 1

Guided checkpoint

Assume a variable-length record with header components A, B, C, D and data fields Name, Address.

ABCDNameAddressOther header information(fixed-size)Pointer tonamePointer toaddress
  • A = 8 bytes
  • B = 4 bytes
  • C = 2 bytes (pointer to Name)
  • D = 2 bytes (pointer to Address)

Data table (numbers in parentheses are bytes for value storage):

NameAddress
John Doe (8)3734 Capitol Avenue (19)
Bruce Wayne (11)461 Still Street (16)
George Cross (12)1001 Clover Drive (17)
Johnny Riely (12)4919 Modoc Alley (16)
Alfred Thaddeus Crane (21)3895 Owagner Lane (17)
Beryl Hutchinson (16)4558 Twin Willow Lane (21)

Furthermore, assume:

  • Each variable-sized field needs 2 additional bytes besides raw storage.
  • Each page has a fixed 12-byte page header.
  • Records are stored as row store (NSM).
  • Records can span multiple blocks; no extra overhead besides record storage.
  • Records can be placed one after another with no additional overhead.

Page 1

R1 R2 ...

Page 2

... R2 R3 R4

Page 3

R5

Page 4

... R5 R6

Page N

...R(X)
...

How many pages are required if the page size is 256 bytes?

03

CLOCK (Second Chance): final cache content

Final order clockwise from top: 12, 6, 81, 15, 69, 55, 42, 3.

Guided checkpoint

Consider the CLOCK (a.k.a. Second Chance) algorithm. The system cache has space for 8 pages, and the current content of the cache is shown below.

126283473670525Cached page: 5Reference bit: 123Cached page: 23Reference bit: 0

When a page is accessed and already in cache, its reference bit is set to 1 (or remains 1). The clock hand does not move in that case.

The clock hand only moves when the accessed page is not in cache and the algorithm searches clockwise for a victim to evict. A newly inserted page gets reference bit 1.

Red boxes indicate reference bit = 1, orange boxes indicate reference bit = 0.

Request sequence:

81, 15, 36, 6, 42, 3, 69, 55

Fill the pages in the clock after the last request is completed (all pages in the sequence have been accessed).

Section 06

Can A1 be answered from the resulting tuples from A2? to How many cache misses occur with FIFO?

01

Can A1 be answered from the resulting tuples from A2?

Die richtige Antwort ist 'Falsch'.

Guided checkpoint

Consider the following queries A1 and A2:

A1: SELECT name FROM R WHERE age > 25
A2: SELECT * FROM R WHERE age > 40

02

How many cache hits occur with FIFO?

Die richtige Antwort ist: 2.

Guided checkpoint

The cache can hold 3 pages and is initially empty. Consider the following page request sequence:

15, 4, 6, 15, 10, 11, 6, 9, 12, 1

How many cache hits occur if the replacement policy is FIFO?

Cache Hit: page is found in cache. Cache Miss: page is not found; writes to empty cache are misses.

03

How many cache misses occur with FIFO?

Die richtige Antwort ist: 8.

Guided checkpoint

The cache can hold 3 pages and is initially empty. Consider the following page request sequence:

15, 4, 6, 15, 9, 11, 6, 12, 15, 9

How many cache misses occur if the replacement policy is FIFO?

Cache Hit: page is found in cache. Cache Miss: page is not found; writes to empty cache are misses.

Section 07

How many cache hits occur with LRU? to Disk Summary: label A, B, C, D

01

How many cache hits occur with LRU?

Die richtige Antwort ist: 2.

Guided checkpoint

The cache can hold 3 pages and is initially empty. Consider the following page request sequence:

15, 4, 6, 15, 9, 11, 6, 9, 12, 1

How many cache hits occur if the replacement policy is LRU?

Cache Hit: page is found in cache. Cache Miss: page is not found; writes to empty cache are misses.

02

Given this workload, which caching strategy is more efficient?

Die richtige Antwort ist: LRU.

Guided checkpoint

A query plan has a burst access pattern: it accesses a particular section of data at a time and then never accesses that section again.

Choose one answer.

03

Disk Summary: label A, B, C, D

A=track, B=segment, C=sector, D=cluster/block.

Guided checkpoint

Use the blank disk summary figure and assign the correct label to A, B, C, and D.

Blank disk summary diagram with markers A, B, C, D

Select the correct term for each marker:

Knowledge check

Turn understanding into recall.

The quiz now follows the same concepts in scored form. You can return to this lesson from the quiz whenever a gap appears.