Buffer Pool

COMP9315 23T1 ♢ Buffer Pool ♢ [0/16]
❖ Buffer Pool


[Diagram:Pics/storage/dbmsarch2.png]

COMP9315 23T1 ♢ Buffer Pool ♢ [1/16]
❖ Buffer Pool (cont)

Aim of buffer pool:

Used by: Uses:
Note: we use the terms page and block interchangably
COMP9315 23T1 ♢ Buffer Pool ♢ [2/16]
❖ Buffer Pool (cont)

[Diagram:Pics/storage/pool.png]

COMP9315 23T1 ♢ Buffer Pool ♢ [3/16]
❖ Buffer Pool (cont)

Buffer pool operations:   (both take single PageID argument)

To some extent ...

Buffer pool data structures:

COMP9315 23T1 ♢ Buffer Pool ♢ [4/16]
❖ Buffer Pool (cont)

[Diagram:Pics/storage/buffer-pool.png]

COMP9315 23T1 ♢ Buffer Pool ♢ [5/16]
❖ Buffer Pool (cont)

For each frame, we need to know:   (FrameData)


Pages are referenced by PageID ...
COMP9315 23T1 ♢ Buffer Pool ♢ [6/16]
❖ Buffer Pool (cont)

How scans are performed without Buffer Pool:

Buffer buf;
int N = numberOfBlocks(Rel);
for (i = 0; i < N; i++) {
   pageID = makePageID(db,Rel,i);
   getBlock(pageID, buf);
   for (j = 0; j < nTuples(buf); j++)
      process(buf, j)
}

Requires N page reads.

If we read it again, N page reads.

COMP9315 23T1 ♢ Buffer Pool ♢ [7/16]
❖ Buffer Pool (cont)

How scans are performed with Buffer Pool:

Buffer buf;
int N = numberOfBlocks(Rel);
for (i = 0; i < N; i++) {
   pageID = makePageID(db,Rel,i);
   bufID = request_page(pageID);
   buf = frames[bufID]
   for (j = 0; j < nTuples(buf); j++)
      process(buf, j)
   release_page(pageID);
}

Requires N page reads on the first pass.

If we read it again, 0 ≤ page reads ≤ N

COMP9315 23T1 ♢ Buffer Pool ♢ [8/16]
❖ Buffer Pool (cont)

Implementation of request_page()

int request_page(PageID pid)
{
   if (pid in Pool)
      bufID = index for pid in Pool
   else {
      if (no free frames in Pool)
         evict a page (free a frame)
      bufID = allocate free frame
      directory[bufID].page = pid
      directory[bufID].pin_count = 0
      directory[bufID].dirty_bit = 0
   }
   directory[bufID].pin_count++
   return bufID
}

COMP9315 23T1 ♢ Buffer Pool ♢ [9/16]
❖ Buffer Pool (cont)

The release_page(pid) operation:

Note: no effect on disk or buffer contents until replacement required

The mark_page(pid) operation:

Note: doesn't actually write to disk; indicates that page changed

The flush_page(pid) operation:

Note: not generally used by higher levels of DBMS

COMP9315 23T1 ♢ Buffer Pool ♢ [10/16]
❖ Buffer Pool (cont)

Evicting a page ...

If multiple frames can potentially be released
COMP9315 23T1 ♢ Buffer Pool ♢ [11/16]
❖ Page Replacement Policies

Several schemes are commonly in use:

LRU / MRU require knowledge of when pages were last accessed
COMP9315 23T1 ♢ Buffer Pool ♢ [12/16]
❖ Page Replacement Policies (cont)

Cost benefit from buffer pool (with n frames) is determined by:

Example (a): sequential scan, LRU or MRU, n ≥ b

First scan costs b reads; subsequent scans are "free".

Example (b): sequential scan, MRU, n < b

First scan costs b reads; subsequent scans cost b - n reads.

Example (c): sequential scan, LRU, n < b

All scans cost b reads; known as sequential flooding.

COMP9315 23T1 ♢ Buffer Pool ♢ [13/16]
❖ Effect of Buffer Management

Consider a query to find customers who are also employees:

select c.name
from   Customer c, Employee e
where  c.ssn = e.ssn;

This might be implemented inside the DBMS via nested loops:

for each tuple t1 in Customer {
    for each tuple t2 in Employee {
        if (t1.ssn == t2.ssn)
            append (t1.name) to result set
    }
}

COMP9315 23T1 ♢ Buffer Pool ♢ [14/16]
❖ Effect of Buffer Management (cont)

In terms of page-level operations, the algorithm looks like:

Rel rC = openRelation("Customer");
Rel rE = openRelation("Employee");
for (int i = 0; i < nPages(rC); i++) {
    PageID pid1 = makePageID(db,rC,i);
    Page p1 = request_page(pid1);
    for (int j = 0; j < nPages(rE); j++) {
        PageID pid2 = makePageID(db,rE,j);
        Page p2 = request_page(pid2);
        // compare all pairs of tuples from p1,p2
        // construct solution set from matching pairs
        release_page(pid2);
    }
    release_page(pid1);
}

COMP9315 23T1 ♢ Buffer Pool ♢ [15/16]
❖ Effect of Buffer Management (cont)

Costs depend on relative size of tables, #buffers (n), replacement strategy

Requests: each rC page requested once, each rE page requested rC times

If nPages(rC)+nPages(rE) ≤ n

If nPages(rE) ≤ n-1, and LRU replacement If n == 2   (worst case)
COMP9315 23T1 ♢ Buffer Pool ♢ [16/16]


Produced: 20 Feb 2023