COMP SCI 564: DBMS

Midterm, Fall 2022 (Lecture: AnHai Doan; Slide: AnHai Doan, Paris Koutris, R. Ramakrishnan)

Ruixuan Tu (ruixuan.tu@wisc.edu), University of Wisconsin-Madison


ER model

role: ; weak entity set:

Relational model and translating ER to relational

SQL

SELECT C.Name AS Country, MAX(T.Population) AS N FROM Country C, City T
  WHERE C.Code = T.CountryCode GROUP BY C.Name;
SELECT-FROM ... INNER JOIN City T ON C.Code = T.CountryCode GROUP BY C.Name;

Storage and buffer management

def access(REQUESTED_PAGE_ID):
  if REQUESTED_PAGE_ID not in POOL:
    FRAME_FOR_REPLACEMENT = replacement_policy()
    if FRAME_FOR_REPLACEMENT.page.dirty:  # if modified
      disk_write(FRAME_FOR_REPLACEMENT.page)  # flush
    FRAME_FOR_REPLACEMENT = disk_read(REQUESTED_PAGE_ID)
  POOL[REQUESTED_PAGE_ID].pin_count += 1  # candidate for replacement iff pin_count == 0
  return REQUESTED_PAGE
def release(REQUESTED_PAGE_ID):  # must call when done
  POOL[REQUESTED_PAGE_ID].pin_count -= 1
P = RandPage(); // clock hand
if (P.Used == True) { P.Used = False;
  if (P == len(AllPages)) P = 0; // back to front
  else P++; }
else Evict(P)

File organization and indexing