Presentation is loading. Please wait.

Presentation is loading. Please wait.

15.7 BUFFER MANAGEMENT. 15.7.1 Buffer Management Architecture The buffer manager controls main memory directly, as in many relational DBMS’s The buffer.

Similar presentations


Presentation on theme: "15.7 BUFFER MANAGEMENT. 15.7.1 Buffer Management Architecture The buffer manager controls main memory directly, as in many relational DBMS’s The buffer."— Presentation transcript:

1 15.7 BUFFER MANAGEMENT

2 15.7.1 Buffer Management Architecture The buffer manager controls main memory directly, as in many relational DBMS’s The buffer manager allocates buffers in virtual memory, allowing the operating system to decide which buffers are actually in main memory at any time and which are in the “swap space” on disk that the operating system manages. Many “main- memory” DBMS’s and “object-oriented” DBMS’s operate this way.

3 15.7.1 Buffer Management Architecture (cont.) Buffer manager controls main memory If request exceed available space, it has to select a buffer to empty by returning its contents to disk. If buffered block has not been changed, buffer manager erased the block from main memory. Write the buffered block to disk if changed. Buffer manager controls virtual memory Buffer manager has the option to allocate more buffers than can fit in main memory. Thrashing problem occurs, many blocks are moved in and out of the disk’s swap space

4 15.7.1 Buffer Management Architecture (cont.) Normally, the number of buffers is a parameter set when the DBMS is initialized. We will assumed that there is a fixed-sized buffer pool.

5 15.7.2 Buffer Management Strategies The critical choice that the buffer manager must make is what block to throw out of the buff pool when the buffer is needed for newly requested block. There are some common strategies, such as in operating systems. These include: LRU FIFO Clock System Control

6 15.7.2 Buffer Management Strategies (cont.) LRU – Least recently used Throw out block that has not been read or written for the longest time. FIFO – First in first out The oldest block in the buffer is emptied for the new block Clock – Let blocks in buffer have second chance to live. Clock wisely, buffer manager loops through blocks in buffer and looks for block that hasn’t been accessed for two rounds. Then, replace this block with new block.

7 15.7.2 Buffer Management Strategies (cont.) 0 0 1 1 1 0 0 Start point to search a 0 flag the buffer with a 0 flag will be replaced The flag will be set to 0 By next time the hand reaches it, if the content of this buffer is not accessed, i.e. flag=0, this buffer will be replaced. That’s “Second Chance”. 1

8 15.7.2 Buffer Management Strategies (cont.) System Control Strict used of LRU, FIFO, or Clock can have disadvantage Recall from sect 13.6.5, there are sometimes technical reasons that a block can not be moved to disk without first modifying certain blocks that point to it. These blocks are called “pinned”. (b-tree index) FIFO pin root block of B-tree Similarly, for one-pass hash-join, the query processor may “pin” the blocks of the smaller relation in order to assure that it will remain in main memory during the entire time. Buffer manager has to modify its buffer-replacement strategy to avoid expelling pinned blocks

9 15.7.3 The Relationship Between Physical Operator Selection and Buffer Management The buffer manager may not be willing or able to guarantee the availability of M buffers when the query is executed I.e multiple queries Two questions arise Can the algorithm adapt to the changes in the value of M, the number of main-memory buffers available? When the expected M buffers are not available, and some blocks that are expected to be in the memory have actually been moved to disk by the buffer manager, how does the buffer-replacement strategy used by the buffer manager impact the number of additional I/O’s that must be performed?

10 15.7.3 The Relationship Between Physical Operator Selection and Buffer Management (cont.) FOR each chunk of M(available)-1 blocks of S DO BEGIN read these blocks into main-memory buffers; organize their tuples into a search structure whose search key is the common attributes of R and S; FOR each block b of R DO BEGIN read b into main memory; FOR each tuple t of b DO BEGIN find the tuples of S in main memory that join with t ; output the join of t with each of these tuples; END ; I 1 = 5 blocks 4 blocks of S 1 block of R I 2 = 11 blocks 10 blocks of S 1 block of R

11 15.7.3 The Relationship Between Physical Operator Selection and Buffer Management (cont.) FOR each chunk of M(available)-1 blocks of S DO BEGIN read these blocks into main-memory buffers; organize their tuples into a search structure whose search key is the common attributes of R and S; alternate the order of blocks R (rocking) FOR each block b of R DO BEGIN read b into main memory; FOR each tuple t of b DO BEGIN find the tuples of S in main memory that join with t ; output the join of t with each of these tuples; END ; LRU improvement – alternate the order of blocks R Save I/O for first or last blocks


Download ppt "15.7 BUFFER MANAGEMENT. 15.7.1 Buffer Management Architecture The buffer manager controls main memory directly, as in many relational DBMS’s The buffer."

Similar presentations


Ads by Google