[prev] 38 [next]

Example: Scanning a Relation

With the above disk manager, the query:

select name from Employee

might be implemented as something like

DB db = openDatabase("myDB");
Reln r = openRelation(db,"Employee");
Page buffer = malloc(PAGESIZE*sizeof(char));
for (int i = 0; i < nPages(r); i++) {
   PageId pid = makePageId(r,i);
   get_page(db, pid, buffer);
   foreach tuple in buffer {
      get tuple data and extract name
   }
}