Buffer Pools Lecture # 05 Database Systems Andy Pavlo AP AP Computer Science 15-445/15-645 Carnegie Mellon Univ. Fall 2018
2 UPCO M IN G DATABASE EVEN TS Relational AI Talk → Wednesday Sep 12 th @ 4:00pm → GHC 8102 MapD Talk → Thursday Sept 20 th @ 12pm → CIC 4 th Floor CMU 15-445/645 (Fall 2018)
3 DATABASE STO RAGE Problem #1: How the DBMS represents the database in files on disk. Problem #2: How the DBMS manages its memory and move data back-and-forth from disk. CMU 15-445/645 (Fall 2018)
4 DATABASE STO RAGE Spatial Control: → Where to write pages on disk. → The goal is to keep pages that are used together often as physically close together as possible on disk. Temporal Control: → When to read pages into memory, and when to write them to disk. → The goal is minimize the number of stalls from having to read data from disk. CMU 15-445/645 (Fall 2018)
5 DISK- O RIEN TED DBM S Get page #2 Execution Engine Buffer Pool Directory Header 2 Pointer to page #2 Memory Database File Directory Header Header Header Header Header … 1 2 3 4 5 Pages Disk CMU 15-445/645 (Fall 2018)
6 TO DAY'S AGEN DA Buffer Pool Manager Replacement Policies Allocation Policies Other Memory Pools CMU 15-445/645 (Fall 2018)
7 BUFFER PO O L O RGAN IZATIO N Buffer Memory region organized as an array Pool of fixed-size pages. frame1 page1 An array entry is called a frame. frame2 page3 frame3 When the DBMS requests a page, an exact copy is placed into one of these frame4 frames. page1 page2 page3 page4 On-Disk File CMU 15-445/645 (Fall 2018)
8 BUFFER PO O L M ETA- DATA Page Buffer The page table keeps track of pages Table Pool that are currently in memory. page1 frame1 page1 page3 frame2 page3 Also maintains additional meta-data frame3 per page: → Dirty Flag frame4 → Pin/Reference Counter page1 page2 page3 page4 On-Disk File CMU 15-445/645 (Fall 2018)
8 BUFFER PO O L M ETA- DATA Page Buffer The page table keeps track of pages Table Pool that are currently in memory. page1 frame1 page1 page3 frame2 page3 Also maintains additional meta-data frame3 per page: → Dirty Flag frame4 → Pin/Reference Counter page1 page2 page3 page4 On-Disk File CMU 15-445/645 (Fall 2018)
8 BUFFER PO O L M ETA- DATA Page Buffer The page table keeps track of pages Table Pool that are currently in memory. page1 frame1 page1 page3 frame2 page3 Also maintains additional meta-data frame3 per page: → Dirty Flag frame4 → Pin/Reference Counter page1 page2 page3 page4 On-Disk File CMU 15-445/645 (Fall 2018)
8 BUFFER PO O L M ETA- DATA Page Buffer The page table keeps track of pages Table Pool that are currently in memory. page1 frame1 page1 page3 frame2 page3 Also maintains additional meta-data frame3 page2 per page: → Dirty Flag frame4 → Pin/Reference Counter page1 page2 page3 page4 On-Disk File CMU 15-445/645 (Fall 2018)
8 BUFFER PO O L M ETA- DATA Page Buffer The page table keeps track of pages Table Pool that are currently in memory. page1 frame1 page1 page3 frame2 page3 Also maintains additional meta-data frame3 page2 per page: → Dirty Flag page2 frame4 → Pin/Reference Counter page1 page2 page3 page4 On-Disk File CMU 15-445/645 (Fall 2018)
9 LO CKS VS. LATCH ES Locks: → Protects the database's logical contents from other transactions. → Held for transaction duration. → Need to be able to rollback changes. Latches: → Protects the critical sections of the DBMS's internal data structure from other threads. → Held for operation duration. → Do not need to be able to rollback changes. CMU 15-445/645 (Fall 2018)
10 PAGE TABLE VS. PAGE DIRECTO RY The page directory is the mapping from page ids to page locations in the database files. → All changes must be recorded on disk to allow the DBMS to find on restart. The page table is the mapping from page ids to a copy of the page in buffer pool frames. → This is an in-memory data structure that does not need to be stored on disk. CMU 15-445/645 (Fall 2018)
11 M ULTIPLE BUFFER PO O LS The DBMS does not always have a single buffer pool for the entire system. → Multiple buffer pool instances → Per-database buffer pool → Per-page type buffer pool Helps reduce latch contention and improve locality. CMU 15-445/645 (Fall 2018)
12 PRE- FETCH IN G Disk Pages The DBMS can also prefetch pages based on a query plan. Q1 page0 → Sequential Scans page1 → Index Scans page2 Buffer Pool page3 page4 page5 CMU 15-445/645 (Fall 2018)
12 PRE- FETCH IN G Disk Pages The DBMS can also prefetch pages based on a query plan. Q1 page0 → Sequential Scans page1 → Index Scans page2 Buffer Pool page3 page0 page4 page5 CMU 15-445/645 (Fall 2018)
12 PRE- FETCH IN G Disk Pages The DBMS can also prefetch pages based on a query plan. page0 → Sequential Scans page1 → Index Scans Q1 page2 Buffer Pool page3 page0 page4 page1 page5 CMU 15-445/645 (Fall 2018)
12 PRE- FETCH IN G Disk Pages The DBMS can also prefetch pages based on a query plan. page0 → Sequential Scans page1 → Index Scans Q1 page2 Buffer Pool page3 page0 page4 page1 page5 CMU 15-445/645 (Fall 2018)
12 PRE- FETCH IN G Disk Pages The DBMS can also prefetch pages based on a query plan. page0 → Sequential Scans page1 → Index Scans Q1 page2 Buffer Pool page3 page3 page4 page1 page5 page2 CMU 15-445/645 (Fall 2018)
12 PRE- FETCH IN G Disk Pages The DBMS can also prefetch pages based on a query plan. page0 → Sequential Scans page1 → Index Scans page2 Q1 Buffer Pool page3 page3 page4 page1 page5 page2 CMU 15-445/645 (Fall 2018)
12 PRE- FETCH IN G Disk Pages The DBMS can also prefetch pages based on a query plan. page0 → Sequential Scans page1 → Index Scans page2 Buffer Pool page3 page3 page4 page4 Q1 page5 page5 CMU 15-445/645 (Fall 2018)
13 PRE- FETCH IN G index-page0 Disk Pages index-page1 index-page4 index-page0 index-page2 index-page3 index-page5 index-page6 index-page1 index-page2 Buffer Pool index-page3 index-page4 index-page5 CMU 15-445/645 (Fall 2018)
13 PRE- FETCH IN G index-page0 Disk Pages Q1 index-page1 index-page4 index-page0 index-page2 index-page3 index-page5 index-page6 index-page1 index-page2 Buffer Pool index-page3 index-page0 index-page4 index-page5 CMU 15-445/645 (Fall 2018)
13 PRE- FETCH IN G index-page0 Disk Pages index-page1 index-page4 index-page0 index-page2 index-page3 index-page5 index-page6 index-page1 Q1 index-page2 Buffer Pool index-page3 index-page0 index-page4 index-page1 index-page5 CMU 15-445/645 (Fall 2018)
13 PRE- FETCH IN G index-page0 Disk Pages index-page1 index-page4 index-page0 index-page2 index-page3 index-page5 index-page6 index-page1 Q1 index-page2 Buffer Pool index-page3 index-page0 index-page4 index-page1 index-page5 CMU 15-445/645 (Fall 2018)
14 SCAN SH ARIN G Queries are able to reuse data retrieved from storage or operator computations. → This is different from result caching. Allow multiple queries to attach to a single cursor that scans a table. → Queries do not have to be exactly the same. → Can also share intermediate results. CMU 15-445/645 (Fall 2018)
15 SCAN SH ARIN G If a query starts a scan and if there one already doing this, then the DBMS will attach to the second query's cursor. → The DBMS keeps track of where the second query joined with the first so that it can finish the scan when it reaches the end of the data structure. Fully supported in IBM DB2 and MSSQL. Oracle only supports cursor sharing for identical queries. CMU 15-445/645 (Fall 2018)
16 SCAN SH ARIN G Disk Pages Q1 SELECT SUM (val) FROM A Q1 page0 page1 page2 Buffer Pool page3 page4 page5 CMU 15-445/645 (Fall 2018)
16 SCAN SH ARIN G Disk Pages Q1 SELECT SUM (val) FROM A Q1 page0 page1 page2 Buffer Pool page3 page0 page4 page5 CMU 15-445/645 (Fall 2018)
16 SCAN SH ARIN G Disk Pages Q1 SELECT SUM (val) FROM A page0 page1 page2 Q1 Buffer Pool page3 page0 page4 page1 page5 page2 CMU 15-445/645 (Fall 2018)
16 SCAN SH ARIN G Disk Pages Q1 SELECT SUM (val) FROM A page0 page1 page2 Buffer Pool Q1 page3 page0 page4 page1 page5 page2 CMU 15-445/645 (Fall 2018)
16 SCAN SH ARIN G Disk Pages Q1 SELECT SUM (val) FROM A page0 page1 page2 Buffer Pool Q1 page3 page3 page4 page1 page5 page2 CMU 15-445/645 (Fall 2018)
16 SCAN SH ARIN G Disk Pages Q1 SELECT SUM (val) FROM A Q2 page0 Q2 SELECT AVG (val) FROM A page1 page2 Buffer Pool Q1 page3 page3 page4 page1 page5 page2 CMU 15-445/645 (Fall 2018)
16 SCAN SH ARIN G Disk Pages Q1 SELECT SUM (val) FROM A page0 Q2 SELECT AVG (val) FROM A page1 page2 Buffer Pool Q1 page3 Q2 page3 page4 page1 page5 page2 CMU 15-445/645 (Fall 2018)
16 SCAN SH ARIN G Disk Pages Q1 SELECT SUM (val) FROM A page0 Q2 SELECT AVG (val) FROM A page1 page2 Buffer Pool page3 page3 page4 page4 Q2 Q1 page5 page5 CMU 15-445/645 (Fall 2018)
16 SCAN SH ARIN G Disk Pages Q1 SELECT SUM (val) FROM A Q2 page0 Q2 SELECT AVG (val) FROM A page1 page2 Buffer Pool page3 page3 page4 page4 page5 page5 CMU 15-445/645 (Fall 2018)
Recommend
More recommend