Instructors: Winston Hsu, Hao-Hua Chu Fall 2011 HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2011 This document is supplementary document that was created by referring Minibase Project of Univ. of Wisconsin The slide refers to http://dblab.kaist.ac.kr/Course/minibase/
Architecture of a DBMS Query Query Optimization and Execution Relation Operators File and Access Methods Buffer Management Disk Space Management DB
Minibase Relational Database Management System (RDBMS) made by Wisconsin University for educational purpose Independent implementation of each component is possible No pain to implementing whole DBMS Suitable to understand the internal architecture of DBMS Components Parser / Optimizer / Query Processor/ Heap file / B+-tree index / Buffer pool manager / Disk space management system
Heap-File Page Simple Heap-File Page Structure Operations Heap-File Page consists of page information, data area and slot array. Data area in a Heap-File Page is always compacted. We assume that the supported record data type is only character. Operations Insert / Delete a record in a heap-file page Get a first / next record id Get the data / pointer of a record Get some information
HFPage Structure Page Information Data Area record … … … … … … freePtr short slotCnt; short freePtr; short freeSpace; short type; PageId prevPage; PageId nextPage; PageId curPage; Page Information Data Area record … … … … … … freePtr // -1 if EMPTY SLOT short length; // offset from data[0] short offset; … … … … … … … slot[0]
insertRecord(case 1) Page Information Page Information Data Area … … record Data Area … … … … … … Inserted record … … … … empty … … Inserted slot … … slot[0] slot[0]
insertRecord(case 2) Page Information Page Information record Data Area … … record Data Area … … … … … … Inserted record … Inserted slot … … … … … … … slot[0] slot[0]
deleteRecord Page Information Page Information Data Area record … Removed record Data Area record … … … … … … … … Removed slot … … empty … slot[0] slot[0]
exchangeRecord Page Information Page Information Data Area ABC … … ABCDE Data Area … … … ABCDE … … ABC … … … slot[2] … … slot[2] … slot[0] slot[0]
Return Values of APIs Status insertRecord(char *recPtr, int recLen, RID& rid); If there is not enough space for new record, return DONE Status firstRecord(RID& firstRid); If there is no record in Page, return DONE Status nextRecord (RID curRid, RID& nextRid); If there is no next record in Page, return DONE Others if slotNo or pageNo of a record Id and input parameters are not appropriate, return FAIL
Other int HFPage::available_space(void) sizeof(slot_t) bytes must be reserved for a new slot and cannot be used by a new record. freePtr specifies the offset of the first free bytes in data[] Insert from it Modify it when deleting Check the output with sample_output “dumpPage, this: 0x7fffbcf7fa20” is a pointer value. Ignore it. diff your_output sample_output If there are any questions, you can post them on ptt.cc / CSIE_DBMS.
All You have to do hfpage.C
Try and Test wget http://mll.csie.ntu.edu.tw/course/database_f10/assignment/hfpage11.tar.gz tar -xvvzf hfpage11.tar.gz make hfpage test_driver.C Test code file