homework 3 practical implementation of a simple rational database management system

25
1-1 Homework 3 Practical Implementation of A Simple Rational Database Management System

Upload: cody

Post on 15-Jan-2016

31 views

Category:

Documents


0 download

DESCRIPTION

Homework 3 Practical Implementation of A Simple Rational Database Management System. Contents. Introduction Requirements Submissions Demo Examples. Introduction. Introduction. Front End Provide a friendly user interface. Parse SQL statement into an execution plan. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-1

Homework 3

Practical Implementation of A Simple Rational Database Management System

Page 2: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-2Wei-Pang Yang, Database Lab. CIS, NCTU

Contents

Introduction

Requirements

Submissions

Demo Examples

Page 3: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-3

Introduction

Page 4: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-4Wei-Pang Yang, Database Lab. CIS, NCTU

Introduction Front End

Provide a friendly user interface.

Parse SQL statement into an execution plan.

Display result into a table grid.

Query Processor Translate execution plan into relational

algebra operations.

Storage System Deal with the data storage in files.

Manipulate the internal organization of relations.

Page 5: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-5Wei-Pang Yang, Database Lab. CIS, NCTU

Query in SQL: SELECT CUSTOMER. NAME FROM CUSTOMER, INVOICE WHERE REGION = 'N.Y.' AND AMOUNT > 10000 AND CUTOMER.C#=INVOICE.C

Internal Form :

( (S SP)

Operator : SCAN C using region index, create C SCAN I using amount index, create I SORT C?and I?on C# JOIN C?and I?on C# EXTRACT name field

Calls to Access Method: OPEN SCAN on C with region index GET next tuple . . .

Calls to file system: GET10th to 25th bytes from block #6 of file #5

Language Processor

Optimizer

Operator Processor

Access Method

File System

database

QueryProcessor

Storage Systeme.g.B-tree; Index; Hashing

DBMS

Front End Front End

Page 6: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-6

Requirements

Page 7: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-7Wei-Pang Yang, Database Lab. CIS, NCTU

Requirements Group-work project

3 persons per group.

Single person is not allowed.

Programming language No restriction.

Should provide a friendly UI.

Should deal with SQL commands. MUST follow the syntax of the demo example.

BUT, You can extend the syntax to support other functions.

Page 8: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-8Wei-Pang Yang, Database Lab. CIS, NCTU

Requirements (cont.)

Should achieve basic functions Create and delete relations.

Contain multiple attributes in one relation.

Provide basic attribute type such as integer, real, and string.

Support relational algebra such as select, project, and join.

Support predicate with boolean expression such as AND and OR.

View or save results as a relation.

Insert tuples into a relation.

Update and delete tuples from a relation under a specified condition.

Page 9: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-9Wei-Pang Yang, Database Lab. CIS, NCTU

Requirements (cont.)

More information http://

www.database.cis.nctu.edu.tw/courses/wpyang/2004S-5138/FinalProject2004.htm

Page 10: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-10Wei-Pang Yang, Database Lab. CIS, NCTU

Bonus

Including but not restricted

Query Processor Query optimization.

Storage System B-tree index.

Transaction management.

Page 11: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-11

Submissions

Page 12: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-12Wei-Pang Yang, Database Lab. CIS, NCTU

Submissions Hard copy report

A detail description of system design and implementation.

Including but not restricted• Your own extended syntax of query language.• The system architecture.• The interfaces between components.

Level of participation, such as

student A: 30%, student B: 40%, student C: 30%

Your system in a floppy disk. Source code.

Execution file.

Page 13: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-13Wei-Pang Yang, Database Lab. CIS, NCTU

Deadline

Demo: Location:

The schedule will be announced. Please refer to http://www.database.cis.nctu.edu.tw/courses.

Submissions:

Page 14: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-14Wei-Pang Yang, Database Lab. CIS, NCTU

Grading

Report: 20%.

System demo: 80%

Page 15: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-15

Demo Examples

Page 16: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-16Wei-Pang Yang, Database Lab. CIS, NCTU

Demo Example

Q1: Create Relation Create Table T;

Create Table S (char[2] S#, char[10] Sname, int Status, char[10] City);

Create Table P (char[2] P#, char[10] Pname, real Weight);

Create Table SP (char[2] S#, char[2] P#, int Qty);

Q2: Drop Relation

Drop Table T;

Page 17: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-17Wei-Pang Yang, Database Lab. CIS, NCTU

Demo Example (cont.) Q3: Insert single tuple

Insert into S (S#, Sname, Status, City) value (“S1”,”Smith”,20,”London”); Insert into S (S#, Sname, Status, City) value (“S2”,”Jones”,10,”Paris”); Insert into S (S#, Sname, Status, City) value (“S3”,”Black”,30,”Paris”); Insert into P (P#, Pname, Weight) value (“P1”,”Nut”,17.20); Insert into P (P#, Pname, Weight) value (“P2”,”Bolt”,20); Insert into P (P#, Pname, Weight) value (“P3”,”Screw”,10.50); Insert into P (P#, Pname, Weight) value (“P4”,”Test”,5.5); Insert into SP (S#, P#, Qty) value (“S1”,”P1”,300); Insert into SP (S#, P#, Qty) value (“S1”,”P2”,200); Insert into SP (S#, P#, Qty) value (“S2”,”P2”,400); Insert into SP (S#, P#, Qty) value (“S3”,”P3”,100);

Bonus: Insert multiple tuples Insert into P(P#, Pname, Weight) Select S#, Sname, Status from S where Sta

tus > 10;

Page 18: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-18Wei-Pang Yang, Database Lab. CIS, NCTU

Demo Example (cont.)

Q4: Update Update P Set Pname=”Nutt”, Weight=12.9

Where Weight < 15

Q5: Delete Delete From P Where Weight < 15;

 Q6: Select Select * From S;

Select * From P;

Page 19: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-19Wei-Pang Yang, Database Lab. CIS, NCTU

Demo Example (cont.)

Q7: Select + Project

Select S#,Sname,City From S;

Q8: Select + Join

Select * From S, SP Where S.S#=SP.S#

Q9: Select + Project + Join (two relations)

Select S.S#, SP.P#, SP.Qty From S, SP Where S.S#=SP.S#;

Page 20: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-20Wei-Pang Yang, Database Lab. CIS, NCTU

Demo Example (cont.)

Q10a: Select + Project + Join + And (two relations)

Select S.S#, SP.P#, SP.Qty From S, SP

Where S.S#=SP.S# and SP.Qty < 400;

Q10b: Select + Project + Join + And (more than two re

lations)

Select S.Sname, P.Pname, SP.Qty From S, SP, P

Where S.S#=SP.S# and P.P#=SP.P#;

Page 21: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-21Wei-Pang Yang, Database Lab. CIS, NCTU

Demo Example (cont.)

Q11a: Select + Project + Join + multiple And (two relat

ions)

Select S.S#, SP.P#, SP.Qty From S, SP

Where S.S#=”S1” and S.S#=SP.S# and SP.Qty>200;

Q11b: Select + Project + Join + multiple And (more th

an two relations)

Select S.Sname, P.Pname, SP.Qty From S, SP, P

Where S.S#=”S1” and S.S#=SP.S# and P.P#=SP.P#;

Page 22: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-22Wei-Pang Yang, Database Lab. CIS, NCTU

Demo Example (cont.)

Q12a: Select + Project + Join + And + Or (two relation

s)

Select S.S#, SP.P#, SP.Qty From S, SP

Where S.S#=SP.S# and (SP.Qty >=400 or SP.Qty <=200);

Q12b: Select + Project + Join + And + Or (more than t

wo relations)

Select S.Sname, P.Pname, SP.Qty From S, SP, P

Where S.S#=SP.S# and P.P#=SP.P#

and (S.S#=”S1” or S.S#=”S2”);

Page 23: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-23Wei-Pang Yang, Database Lab. CIS, NCTU

Demo Example (cont.) Q13a: Transaction Abort

Transaction Begin;Insert into S (S#, Sname, Status, City) value (“S4”,”Test”,100,”Taipei”);Transaction Abort;

Select * from S;

 Q13b: Transaction Commit Transaction Begin;

Insert into S (S#, Sname, Status, City) value (“S4”,”Test”,100,”Taipei”);Transaction Commit;

Quit the DBMS process

Select * from S;

Page 24: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-24Wei-Pang Yang, Database Lab. CIS, NCTU

Demo Example (cont.)

Q14a: Create Index

Create Index SI ON S (Status ASC);

Select * from S;

Q14b: Drop Index

Drop Index SI ;

Select * from S;

Q15: Save the query result

Page 25: Homework 3 Practical Implementation of A Simple Rational Database Management System

1-25Wei-Pang Yang, Database Lab. CIS, NCTU

Grading SpecificationCreate Relation /3

Drop Relation /3

Integer Type Operation /3

Real Type Operation/3

String Type Operation /3

Insert a tuple/4

Insert n tuples /4

Update n tuples/4

Delete n tuples/3

Select/4

Select + Project/4

Select + And/4

Select + Or/4

Select + n And/3

Select + n Or/3

Select + And + Or/3

Select + Join/4

Select + Project + Join/4

Select + Project + Join (2)/4

Select + Project + Join + And (2)/4

Select + Project + Join + And (n)/3

Select + Project + Join + n And (2) /3

Select + Project + Join + n And (n)/3

Select + Project + Join + And + Or (2)/4

Select + Project + Join + And + Or (n)/3

Save the result/3

Memo

Transaction Abort/3

Transaction Commit/3

Index Create/Drop/4