Upload
priscilla-golden
View
214
Download
0
Embed Size (px)
Citation preview
CPSC-608 Database Systems
Fall 2015
Instructor: Jianer ChenOffice: HRBB 315CPhone: 845-4259Email: [email protected]
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
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
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
What Does DBMS Do?
• Prepare a collection C of efficient algorithms for operations in relational algebra;
What Does DBMS Do?
• Prepare a collection C of efficient algorithms for operations in relational algebra;
• For a given database program P:
What Does DBMS Do?
• 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?
• 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?
• 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?
• 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?
• 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?
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
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;
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>;
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>;
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
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
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
• 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?
• 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.
SELECT beerFROM Likes, FrequentsWHERE bar = ’Joe’’s Bar’ AND Frequents.drinker =
Likes.drinker;