13
HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 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/

HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 This document is supplementary document that was created by referring Minibase Project

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 This document is supplementary document that was created by referring Minibase Project

HW3: Heap-File Page

Instructors: Winston Hsu, Hao-Hua ChuFall 2010

This document is supplementary document that was created by referring Minibase Project of Univ. of WisconsinThe slide refers to http://dblab.kaist.ac.kr/Course/minibase/

Page 2: HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 This document is supplementary document that was created by referring Minibase Project

Architecture of a DBMSQuery

Query Optimization and Execution

DB

Relation OperatorsFile and Access Methods

Buffer ManagementDisk Space Management

Page 3: HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 This document is supplementary document that was created by referring Minibase Project

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

Page 4: HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 This document is supplementary document that was created by referring Minibase Project

Heap-File Page• Simple Heap-File Page Structure– 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

Page 5: HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 This document is supplementary document that was created by referring Minibase Project

HFPage Structure

Page Information

short slotCnt;short freePtr; short freeSpace;short type;PageId prevPage; PageId nextPage; PageId curPage;

Data Area

slot[0]……

record … … …… … …

… ……… …

// -1 if EMPTY SLOTshort length;

// offset from data[0]short offset;

freePtr

Page 6: HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 This document is supplementary document that was created by referring Minibase Project

insertRecord(case 1)

Page Information

Data Area

slot[0]

…empty

record … …

………

Page Information

Data Area

slot[0]

…Inserted slot

record … …

………

Inserted record… … … …

Page 7: HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 This document is supplementary document that was created by referring Minibase Project

insertRecord(case 2)

Page Information

Data Area

slot[0]

record … …

………

Page Information

Data Area

slot[0]

…Inserted slot

record … …

………

Inserted record… … … …

Page 8: HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 This document is supplementary document that was created by referring Minibase Project

deleteRecord

Page Information

Data Area

slot[0]

record …

…Removed slot

… …

Page Information

Data Area

slot[0]

record …

…empty…

……Removed

record

Page 9: HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 This document is supplementary document that was created by referring Minibase Project

exchangeRecord

Page Information

Data Area

slot[0]

ABC …

…slot[2]

… ABCDE

Page Information

Data Area

………

slot[2]slot[0]

ABC…

…ABCDE …

Page 10: HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 This document is supplementary document that was created by referring Minibase Project

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

Page 11: HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 This document is supplementary document that was created by referring Minibase Project

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.

Page 12: HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 This document is supplementary document that was created by referring Minibase Project

All You have to do

• hfpage.C

Page 13: HW3: Heap-File Page Instructors: Winston Hsu, Hao-Hua Chu Fall 2010 This document is supplementary document that was created by referring Minibase Project

Try and Test

• wget http://mll.csie.ntu.edu.tw/course/database_f10/assignment/hfpage09.tar.gz

• tar -xvvzf hfpage09.tar.gz• make• hfpage• test_driver.C– Test code file