CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email:...

22
CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: [email protected] Notes #6

Transcript of CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email:...

Page 1: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

CPSC-608 Database Systems

Fall 2015

Instructor: Jianer ChenOffice: HRBB 315CPhone: 845-4259Email: [email protected]

Notes #6

Page 2: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

secondarystorage(disks)

databaseadministrator

DDLlanguage

database programmer

DML (query)language

DBMS

file manager

buffermanager

mainmemorybuffers

index/file manager

DML complier

DDL complier

query execution

engine

transaction manager

concurrency control

lock table

logging &recovery

Graduate Database

Page 3: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

secondarystorage(disks)

databaseadministrator

DDLlanguage

database programmer

DML (query)language

DBMS

file manager

buffermanager

mainmemorybuffers

index/file manager

DML complier

DDL complier

query execution

engine

transaction manager

concurrency control

lock table

logging &recovery

Graduate Database

Page 4: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

secondarystorage(disks)

databaseadministrator

DDLlanguage

database programmer

DML (query)language

DBMS

file manager

buffermanager

mainmemorybuffers

index/file manager

DML complier

DDL complier

query execution

engine

transaction manager

concurrency control

lock table

logging &recovery

Graduate Database

Page 5: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

What Does DBMS Do?

Page 6: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

• Prepare a collection C of efficient algorithms for operations in relational algebra;

What Does DBMS Do?

Page 7: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

• Prepare a collection C of efficient algorithms for operations in relational algebra;

• For a given database program P:

What Does DBMS Do?

Page 8: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

• Prepare a collection C of efficient algorithms for operations in relational algebra;

• For a given database program P: 1. understand the program P;

What Does DBMS Do?

Page 9: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

• Prepare a collection C of efficient algorithms for operations in relational algebra;

• For a given database program P: 1. understand the program P; 2. translate the program P into an

expression E in relational algebra;

What Does DBMS Do?

Page 10: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

• Prepare a collection C of efficient algorithms for operations in relational algebra;

• For a given database program P: 1. understand the program P; 2. translate the program P into an

expression E in relational algebra; 3. convert E into an algorithm using

algorithms in the collection C;

What Does DBMS Do?

Page 11: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

• Prepare a collection C of efficient algorithms for operations in relational algebra;

• For a given database program P: 1. understand the program P; 2. translate the program P into an expression E in relational algebra; 3. convert E into an algorithm using

algorithms in the collection C; 4. take care of issues in optimization and security.

What Does DBMS Do?

Page 12: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

• Prepare a collection C of efficient algorithms for operations in relational algebra;

• For a given database program P: 1. understand the program P; 2. translate the program P into an expression E in relational algebra; 3. convert E into an algorithm using

algorithms in the collection C; 4. take care of issues in optimization and security.

What Does DBMS Do?

Page 13: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

secondarystorage(disks)

databaseadministrator

DDLlanguage

database programmer

DML (query)language

DBMS

file manager

buffermanager

mainmemorybuffers

index/file manager

DML complier

DDL complier

query execution

engine

transaction manager

concurrency control

lock table

logging &recovery

Graduate Database

Page 14: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

Suppose that we have relations: Frequents(drinker, bar) and Likes(drinker,

beer)

How do we “understand” SELECT beer

FROM Likes, FrequentsWHERE bar = ’Joe’’s Bar’ AND

Frequents.drinker = Likes.drinker;

Page 15: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

DDL StatementsCREATE TABLE <name> (<list of elements>);CREATE VIEW <name> AS <table construction>;CREATE ASSERTION <name> CHECK (<condition>);CREATE TRIGGER <name>CREATE INDEX <name> ON <table>(<attribute-list>);DROP TABLE <name>;ALTER TABLE <name> ADD <attribute declaration>;ALTER TABLE <name> DROP <attribute>;

DML StatementsSELECT select-list FROM from-list WHERE conditions GROUP BY group-list HAVING conditions;

(subquery) UNION (subquery); (subquery) INTERSECT (subquery); (subquery) EXCEPT (subquery);R CROSS JOIN S;R NATURAL JOIN S;R JOIN S ON <condition>;

INSERT INTO <relation> VALUES (<list of values>); DELETE FROM <relation> WHERE <condition>;UPDATE <relation> SET <list of attribute assignments> WHERE <condition on tuples>;

Page 16: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

DDL StatementsCREATE TABLE <name> (<list of elements>);CREATE VIEW <name> AS <table construction>;CREATE ASSERTION <name> CHECK (<condition>);CREATE TRIGGER <name>CREATE INDEX <name> ON <table>(<attribute-list>);DROP TABLE <name>;ALTER TABLE <name> ADD <attribute declaration>;ALTER TABLE <name> DROP <attribute>;

DML StatementsSELECT select-list FROM from-list WHERE conditions GROUP BY group-list HAVING conditions;

(subquery) UNION (subquery); (subquery) INTERSECT (subquery); (subquery) EXCEPT (subquery);R CROSS JOIN S;R NATURAL JOIN S;R JOIN S ON <condition>;

INSERT INTO <relation> VALUES (<list of values>); DELETE FROM <relation> WHERE <condition>;UPDATE <relation> SET <list of attribute assignments> WHERE <condition on tuples>;

Page 17: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

Symbolsa-z, 0-9, <, >, =, ., ,, ;, “, ”, (, ), [, ], +, -, *, /, *

Lexical Rulesletter ::= a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r| s | t | u | v | w | x | y | zdigit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9integer ::= digit+comp-op ::= < | > | =table-name ::= letter[digit | letter]*attribute-name ::= letter[digit | letter]*column-name ::= [table-name.]attribute-nameliteral ::= “whatever-except-(“)-and-(")”

KeywordsCREATE, TABLE, INT, STR20, DROP, SELECT, DISTINCT, FROM, WHERE, ORDER, BY, DELETE,

FROM,INSERT, INTO, VALUES, NULL, OR, AND, NOT,

TinySQL grammar

lexical rules

Page 18: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

Syntax Rulesstatement ::= create-table-statement | drop-table-statement | select-statement

| delete-statement | insert-statementcreate-table-statement ::= CREATE TABLE table-name(attribute-type-list)attribute-type-list ::= attribute-name data-type | attribute-name data-type, attribute-type-listdata-type ::= INT | STR20drop-table-statement ::= DROP TABLE table-nameselect-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition]

[ORDER BY column-name]select-list ::= * | select-sublistselect-sublist ::= column-name | column-name, select-sublisttable-list ::= table-name | table-name, table-listdelete-statement ::= DELETE FROM table-name [WHERE search-condition]insert-statement ::= INSERT INTO table-name(attribute-list) insert-tuplesinsert-tuples ::= VALUES (value-list) | select-statementattribute-list ::= attribute-name | attribute-name, attribute-listvalue ::= literal | integer | NULLvalue-list ::= value | value, value-listsearch-condition ::= boolean-term | boolean-term OR search-conditionboolean-term ::= boolean-factor | boolean-factor AND boolean-termboolean-factor ::= [NOT] boolean-primaryboolean-primary ::= comparison-predicate | "[" search-condition "]"comparison-predicate ::= expression comp-op expressionexpression ::= term | term + expression | term - expressionterm ::= factor | factor * term | factor / termfactor ::= column-name | literal | integer | ( expression )

TinySQL grammar

syntax rules

Page 19: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

Syntax Rulesstatement ::= create-table-statement | drop-table-statement | select-statement

| delete-statement | insert-statementcreate-table-statement ::= CREATE TABLE table-name(attribute-type-list)attribute-type-list ::= attribute-name data-type | attribute-name data-type, attribute-type-listdata-type ::= INT | STR20drop-table-statement ::= DROP TABLE table-nameselect-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition]

[ORDER BY column-name]select-list ::= * | select-sublistselect-sublist ::= column-name | column-name, select-sublisttable-list ::= table-name | table-name, table-listdelete-statement ::= DELETE FROM table-name [WHERE search-condition]insert-statement ::= INSERT INTO table-name(attribute-list) insert-tuplesinsert-tuples ::= VALUES (value-list) | select-statementattribute-list ::= attribute-name | attribute-name, attribute-listvalue ::= literal | integer | NULLvalue-list ::= value | value, value-listsearch-condition ::= boolean-term | boolean-term OR search-conditionboolean-term ::= boolean-factor | boolean-factor AND boolean-termboolean-factor ::= [NOT] boolean-primaryboolean-primary ::= comparison-predicate | "[" search-condition "]"comparison-predicate ::= expression comp-op expressionexpression ::= term | term + expression | term - expressionterm ::= factor | factor * term | factor / termfactor ::= column-name | literal | integer | ( expression )

TinySQL grammar

syntax rules

nonterminals

Page 20: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

• Prepare a collection C of efficient algorithms for operations in relational algebra;

• For a given database program P: 1. understand the program P; 2. translate the program P into an expression E in relational algebra; 3. convert E into an algorithm using

algorithms in the collection C; 4. take care of issues in optimization and security.

What Does DBMS Do?

Page 21: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

• Prepare a collection C of efficient algorithms for operations in relational algebra;

• For a given database program P: 1. understand the program P; 2. translate the program P into an expression E in relational algebra; 3. convert E into an algorithm using

algorithms in the collection C; 4. take care of issues in optimization and security.

What Does DBMS Do?

Start with a single node labeled “<statement>” , repeatedly pick a

leaf that is a nonterminal, and give it its children using a syntax rule.

Page 22: CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #6.

SELECT beerFROM Likes, FrequentsWHERE bar = ’Joe’’s Bar’ AND Frequents.drinker =

Likes.drinker;