Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC-608 Database Systems

Similar presentations


Presentation on theme: "CPSC-608 Database Systems"— Presentation transcript:

1 CPSC-608 Database Systems
Fall 2018 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #12

2 Graduate Database DBMS lock table DDL language DDL complier file
administrator DDL complier lock table DDL language file manager logging & recovery concurrency control transaction manager database programmer index/file manager buffer manager query execution engine DML complier main memory buffers DML (query) language secondary storage (disks) DBMS Graduate Database

3 What Does DBMS Do? Prepare a collection A 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 A; take care of issues in optimization, consistency, and security.

4 What Does DBMS Do? Prepare a collection A of efficient algorithms for operations in relational algebra; For a given database program P: 1. understand the program P; Break the program P into “words” (lexical analysis);

5 What Does DBMS Do? Prepare a collection A of efficient algorithms for operations in relational algebra; For a given database program P: 1. understand the program P; Break the program P into “words” (lexical analysis); Use the language grammar to “parse” the program P.

6 DDL Statements CREATE 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 Statements SELECT 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>;

7 reserved words i.e., keyword DDL Statements
CREATE 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 Statements SELECT 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>; reserved words i.e., keyword

8 syntax rules TinySQL grammar Syntax Rules
statement ::= create-table-statement | drop-table-statement | select-statement | delete-statement | insert-statement create-table-statement ::= CREATE TABLE table-name(attribute-type-list) attribute-type-list ::= attribute-name data-type | attribute-name data-type, attribute-type-list data-type ::= INT | STR20 drop-table-statement ::= DROP TABLE table-name select-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition] [ORDER BY column-name] select-list ::= * | select-sublist select-sublist ::= column-name | column-name, select-sublist table-list ::= table-name | table-name, table-list delete-statement ::= DELETE FROM table-name [WHERE search-condition] insert-statement ::= INSERT INTO table-name(attribute-list) insert-tuples insert-tuples ::= VALUES (value-list) | select-statement attribute-list ::= attribute-name | attribute-name, attribute-list value ::= literal | integer | NULL value-list ::= value | value, value-list search-condition ::= boolean-term | boolean-term OR search-condition boolean-term ::= boolean-factor | boolean-factor AND boolean-term boolean-factor ::= [NOT] boolean-primary boolean-primary ::= comparison-predicate | "[" search-condition "]" comparison-predicate ::= expression comp-op expression expression ::= term | term + expression | term - expression term ::= column-name | literal | integer | (expression) TinySQL grammar syntax rules

9 syntax rules TinySQL grammar nonterminals nonterminal keyword
statement ::= create-table-statement | drop-table-statement | select-statement | delete-statement | insert-statement create-table-statement ::= CREATE TABLE table-name(attribute-type-list) attribute-type-list ::= attribute-name data-type | attribute-name data-type, attribute-type-list data-type ::= INT | STR20 drop-table-statement ::= DROP TABLE table-name select-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition] [ORDER BY column-name] select-list ::= * | select-sublist select-sublist ::= column-name | column-name, select-sublist table-list ::= table-name | table-name, table-list delete-statement ::= DELETE FROM table-name [WHERE search-condition] insert-statement ::= INSERT INTO table-name(attribute-list) insert-tuples insert-tuples ::= VALUES (value-list) | select-statement attribute-list ::= attribute-name | attribute-name, attribute-list value ::= literal | integer | NULL value-list ::= value | value, value-list search-condition ::= boolean-term | boolean-term OR search-condition boolean-term ::= boolean-factor | boolean-factor AND boolean-term boolean-factor ::= [NOT] boolean-primary boolean-primary ::= comparison-predicate | "[" search-condition "]" comparison-predicate ::= expression comp-op expression expression ::= term | term + expression | term - expression term ::= column-name | literal | integer | (expression) nonterminal keyword words returned by SCANNER TinySQL grammar syntax rules

10 syntax rules For each nonterminal, write a subroutine to handle it.
nonterminals Syntax Rules statement ::= create-table-statement | drop-table-statement | select-statement | delete-statement | insert-statement create-table-statement ::= CREATE TABLE table-name(attribute-type-list) attribute-type-list ::= attribute-name data-type | attribute-name data-type, attribute-type-list data-type ::= INT | STR20 drop-table-statement ::= DROP TABLE table-name select-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition] [ORDER BY column-name] select-list ::= * | select-sublist select-sublist ::= column-name | column-name, select-sublist table-list ::= table-name | table-name, table-list delete-statement ::= DELETE FROM table-name [WHERE search-condition] insert-statement ::= INSERT INTO table-name(attribute-list) insert-tuples insert-tuples ::= VALUES (value-list) | select-statement attribute-list ::= attribute-name | attribute-name, attribute-list value ::= literal | integer | NULL value-list ::= value | value, value-list search-condition ::= boolean-term | boolean-term OR search-condition boolean-term ::= boolean-factor | boolean-factor AND boolean-term boolean-factor ::= [NOT] boolean-primary boolean-primary ::= comparison-predicate | "[" search-condition "]" comparison-predicate ::= expression comp-op expression expression ::= term | term + expression | term - expression term ::= column-name | literal | integer | (expression) For each nonterminal, write a subroutine to handle it. TinySQL grammar syntax rules

11 select-statement ::= SELECT [DISTINCT] select-list
FROM table-list [WHERE search-condition] [ORDER BY column-name]

12 select-statement ::= SELECT [DISTINCT] select-list
FROM table-list [WHERE search-condition] [ORDER BY column-name] SELECT-STMT 1. w = SCANNER(); \\ w = “SELECT” 2. w = SCANNER(); 3. if w = “DISTINCT” then w = SCANNER(); 4. CALL SELECT-LIST; 5. w = SCANNER(); \\ w = “FROM” 6. CALL TABLE-LIST; 7. w = SCANNER(); 8. if w = “WHERE” then CALL SEARCH-CONDITION w = SCANNER(); 9. if w = “ORDER” then w = SCANNER(); \\ w = “BY” w = SCANNER(); \\w = column-name

13 Be careful with “pre-read” words
select-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition] [ORDER BY column-name] SELECT-STMT 1. w = SCANNER(); \\ w = “SELECT” 2. w = SCANNER(); 3. if w = “DISTINCT” then w = SCANNER(); 4. CALL SELECT-LIST; 5. w = SCANNER(); \\ w = “FROM” 6. CALL TABLE-LIST; 7. w = SCANNER(); 8. if w = “WHERE” then CALL SEARCH-CONDITION w = SCANNER(); 9. if w = “ORDER” then w = SCANNER(); \\ w = “BY” w = SCANNER(); \\w = column-name Be careful with “pre-read” words

14 What Does DBMS Do? Prepare a collection A of efficient algorithms for operations in relational algebra; For a given database program P: 1. understand the program P; Break the program P into “words” (lexical analysis); Use the language grammar to “parse” the program P;

15 What Does DBMS Do? Prepare a collection A of efficient algorithms for operations in relational algebra; For a given database program P: 1. understand the program P; Break the program P into “words” (lexical analysis); Use the language grammar to “parse” the program P; Make a parse tree for the program P.

16 What Does DBMS Do? Prepare a collection A of efficient algorithms for operations in relational algebra; For a given database program P: 1. understand the program P; Break the program P into “words” (lexical analysis); Use the language grammar to “parse” the program P; Make a parse tree for the program P. What is this?

17 What Does DBMS Do? Prepare a collection A of efficient algorithms for operations in relational algebra; For a given database program P: 1. understand the program P; Break the program P into “words” (lexical analysis); Use the language grammar to “parse” the program P; Make a parse tree for the program P. What is this? A tree structure that shows how the program P follows the grammar rules

18 SQL program P SELECT beer FROM Likes, Frequents WHERE Frequents.drinker = Likes.drinker;

19 SQL program P SELECT beer FROM Likes, Frequents WHERE Frequents.drinker = Likes.drinker; select-statement SELECT select-list select-sublist column-name beer FROM table-list table-name , Linkes Frequents WHERE search-condition boolean-term boolean-factor boolean-primary comparison-predicte expression comp-op = term column-name Frequents.drinker Likes.drinker

20 SQL program P SELECT beer FROM Likes, Frequents WHERE Frequents.drinker = Likes.drinker; select-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition] [ORDER BY column-name] select-list ::= * | select-sublist select-sublist ::= column-name | column-name, select-sublist table-list ::= table-name | table-name, table-list search-condition ::= boolean-term | …… boolean-term ::= boolean-factor | …… boolean-factor ::= [NOT] boolean-primary boolean-primary ::= comparison-predicate | …… comparison-predicate ::= expression comp-op expression expression ::= term | ……| …… term ::= column-name | … | … | … select-statement SELECT select-list select-sublist column-name beer FROM table-list table-name , Linkes Frequents WHERE search-condition boolean-term boolean-factor boolean-primary comparison-predicte expression comp-op = term column-name Frequents.drinker Likes.drinker

21 SQL program P SELECT beer FROM Likes, Frequents WHERE Frequents.drinker = Likes.drinker; select-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition] [ORDER BY column-name] select-list ::= * | select-sublist select-sublist ::= column-name | column-name, select-sublist table-list ::= table-name | table-name, table-list search-condition ::= boolean-term | …… boolean-term ::= boolean-factor | …… boolean-factor ::= [NOT] boolean-primary boolean-primary ::= comparison-predicate | …… comparison-predicate ::= expression comp-op expression expression ::= term | ……| …… term ::= column-name | … | … | … select-statement SELECT select-list select-sublist column-name beer FROM table-list table-name , Linkes Frequents WHERE search-condition boolean-term boolean-factor boolean-primary comparison-predicte expression comp-op = term column-name Frequents.drinker Likes.drinker

22 SQL program P SELECT beer FROM Likes, Frequents WHERE Frequents.drinker = Likes.drinker; select-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition] [ORDER BY column-name] select-list ::= * | select-sublist select-sublist ::= column-name | column-name, select-sublist table-list ::= table-name | table-name, table-list search-condition ::= boolean-term | …… boolean-term ::= boolean-factor | …… boolean-factor ::= [NOT] boolean-primary boolean-primary ::= comparison-predicate | …… comparison-predicate ::= expression comp-op expression expression ::= term | ……| …… term ::= column-name | … | … | … select-statement SELECT select-list FROM table-list WHERE search-condition boolean-term select-sublist table-name , table-list boolean-factor column-name Linkes table-name boolean-primary beer Frequents comparison-predicte expression comp-op expression term = term column-name column-name Frequents.drinker Likes.drinker

23 SQL program P SELECT beer FROM Likes, Frequents WHERE Frequents.drinker = Likes.drinker; select-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition] [ORDER BY column-name] select-list ::= * | select-sublist select-sublist ::= column-name | column-name, select-sublist table-list ::= table-name | table-name, table-list search-condition ::= boolean-term | …… boolean-term ::= boolean-factor | …… boolean-factor ::= [NOT] boolean-primary boolean-primary ::= comparison-predicate | …… comparison-predicate ::= expression comp-op expression expression ::= term | ……| …… term ::= column-name | … | … | … select-statement SELECT select-list FROM table-list WHERE search-condition boolean-term select-sublist table-name , table-list boolean-factor column-name Linkes table-name boolean-primary beer Frequents comparison-predicte expression comp-op expression term = term column-name column-name Frequents.drinker Likes.drinker

24 SQL program P SELECT beer FROM Likes, Frequents WHERE Frequents.drinker = Likes.drinker; select-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition] [ORDER BY column-name] select-list ::= * | select-sublist select-sublist ::= column-name | column-name, select-sublist table-list ::= table-name | table-name, table-list search-condition ::= boolean-term | …… boolean-term ::= boolean-factor | …… boolean-factor ::= [NOT] boolean-primary boolean-primary ::= comparison-predicate | …… comparison-predicate ::= expression comp-op expression expression ::= term | ……| …… term ::= column-name | … | … | … select-statement SELECT select-list FROM table-list WHERE search-condition boolean-term select-sublist table-name , table-list boolean-factor column-name Linkes table-name boolean-primary beer Frequents comparison-predicte expression comp-op expression term = term column-name column-name Frequents.drinker Likes.drinker

25 SQL program P SELECT beer FROM Likes, Frequents WHERE Frequents.drinker = Likes.drinker; select-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition] [ORDER BY column-name] select-list ::= * | select-sublist select-sublist ::= column-name | column-name, select-sublist table-list ::= table-name | table-name, table-list search-condition ::= boolean-term | …… boolean-term ::= boolean-factor | …… boolean-factor ::= [NOT] boolean-primary boolean-primary ::= comparison-predicate | …… comparison-predicate ::= expression comp-op expression expression ::= term | ……| …… term ::= column-name | … | … | … select-statement SELECT select-list FROM table-list WHERE search-condition boolean-term select-sublist table-name , table-list boolean-factor column-name Linkes table-name boolean-primary beer Frequents comparison-predicte expression comp-op expression term = term column-name column-name Frequents.drinker Likes.drinker

26 SQL program P SELECT beer FROM Likes, Frequents WHERE Frequents.drinker = Likes.drinker; select-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition] [ORDER BY column-name] select-list ::= * | select-sublist select-sublist ::= column-name | column-name, select-sublist table-list ::= table-name | table-name, table-list search-condition ::= boolean-term | …… boolean-term ::= boolean-factor | …… boolean-factor ::= [NOT] boolean-primary boolean-primary ::= comparison-predicate | …… comparison-predicate ::= expression comp-op expression expression ::= term | ……| …… term ::= column-name | … | … | … select-statement SELECT select-list FROM table-list WHERE search-condition boolean-term select-sublist table-name , table-list boolean-factor column-name Linkes table-name boolean-primary beer Frequents comparison-predicte expression comp-op expression term = term column-name column-name Frequents.drinker Likes.drinker

27 SQL program P SELECT beer FROM Likes, Frequents WHERE Frequents.drinker = Likes.drinker; select-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition] [ORDER BY column-name] select-list ::= * | select-sublist select-sublist ::= column-name | column-name, select-sublist table-list ::= table-name | table-name, table-list search-condition ::= boolean-term | …… boolean-term ::= boolean-factor | …… boolean-factor ::= [NOT] boolean-primary boolean-primary ::= comparison-predicate | …… comparison-predicate ::= expression comp-op expression expression ::= term | ……| …… term ::= column-name | … | … | … select-statement SELECT select-list FROM table-list WHERE search-condition boolean-term select-sublist table-name , table-list boolean-factor column-name Linkes table-name boolean-primary beer Frequents comparison-predicte expression comp-op expression term = term column-name column-name Frequents.drinker Likes.drinker

28 How is this implemented?
SQL program P SELECT beer FROM Likes, Frequents WHERE Frequents.drinker = Likes.drinker; select-statement ::= SELECT [DISTINCT] select-list FROM table-list [WHERE search-condition] [ORDER BY column-name] select-list ::= * | select-sublist select-sublist ::= column-name | column-name, select-sublist table-list ::= table-name | table-name, table-list search-condition ::= boolean-term | …… boolean-term ::= boolean-factor | …… boolean-factor ::= [NOT] boolean-primary boolean-primary ::= comparison-predicate | …… comparison-predicate ::= expression comp-op expression expression ::= term | ……| …… term ::= column-name | … | … | … select-statement SELECT select-list FROM table-list WHERE search-condition boolean-term select-sublist table-name , table-list boolean-factor column-name Linkes table-name boolean-primary beer Frequents comparison-predicte expression comp-op expression term = term How is this implemented? column-name column-name Frequents.drinker Likes.drinker

29 select-statement ::= SELECT [DISTINCT] select-list
FROM table-list [WHERE search-condition] [ORDER BY column-name] SELECT-STMT 1. w = SCANNER(); \\ w = “SELECT” 2. w = SCANNER(); 3. if w = “DISTINCT” then w = SCANNER(); 4. CALL SELECT-LIST; 5. w = SCANNER(); \\ w = “FROM” 6. CALL TABLE-LIST; 7. w = SCANNER(); 8. if w = “WHERE” then CALL SEARCH-CONDITION w = SCANNER(); 9. if w = “ORDER” then w = SCANNER(); \\ w = “BY” w = SCANNER(); \\w = column-name

30 select-statement ::= SELECT [DISTINCT] select-list FROM table-list
[WHERE search-condition] [ORDER BY column-name] SELECT-STMT 1. w = SCANNER(); \\ w = “SELECT” 2. w = SCANNER(); 3. if w = “DISTINCT” then w = SCANNER(); 4. CALL SELECT-LIST; 5. w = SCANNER(); \\ w = “FROM” 6. CALL TABLE-LIST; 7. w = SCANNER(); 8. if w = “WHERE” then CALL SEARCH-CONDITION w = SCANNER(); 9. if w = “ORDER” then w = SCANNER(); \\ w = “BY” w = SCANNER(); \\w = column-name <= create a node v for select-statement <= make w a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make w a child of v <= make w a child of v

31 select-statement ::= SELECT [DISTINCT] select-list FROM table-list
[WHERE search-condition] [ORDER BY column-name] SELECT FROM WHERE From SELECT-LIST From TABLE-LIST From SEARCH-CONDITION SELECT-STMT 1. w = SCANNER(); \\ w = “SELECT” 2. w = SCANNER(); 3. if w = “DISTINCT” then w = SCANNER(); 4. CALL SELECT-LIST; 5. w = SCANNER(); \\ w = “FROM” 6. CALL TABLE-LIST; 7. w = SCANNER(); 8. if w = “WHERE” then CALL SEARCH-CONDITION w = SCANNER(); 9. if w = “ORDER” then w = SCANNER(); \\ w = “BY” w = SCANNER(); \\w = column-name <= create a node v for select-statement <= make w a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make w a child of v <= make w a child of v

32 select-statement ::= SELECT [DISTINCT] select-list FROM table-list
[WHERE search-condition] [ORDER BY column-name] SELECT FROM WHERE From SELECT-LIST From TABLE-LIST From SEARCH-CONDITION SELECT-STMT 1. w = SCANNER(); \\ w = “SELECT” 2. w = SCANNER(); 3. if w = “DISTINCT” then w = SCANNER(); 4. CALL SELECT-LIST; 5. w = SCANNER(); \\ w = “FROM” 6. CALL TABLE-LIST; 7. w = SCANNER(); 8. if w = “WHERE” then CALL SEARCH-CONDITION w = SCANNER(); 9. if w = “ORDER” then w = SCANNER(); \\ w = “BY” w = SCANNER(); \\w = column-name <= create a node v for select-statement <= make w a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make w a child of v <= make w a child of v

33 select-statement ::= SELECT [DISTINCT] select-list FROM table-list
[WHERE search-condition] [ORDER BY column-name] SELECT FROM WHERE From SELECT-LIST From TABLE-LIST From SEARCH-CONDITION SELECT-STMT 1. w = SCANNER(); \\ w = “SELECT” 2. w = SCANNER(); 3. if w = “DISTINCT” then w = SCANNER(); 4. CALL SELECT-LIST; 5. w = SCANNER(); \\ w = “FROM” 6. CALL TABLE-LIST; 7. w = SCANNER(); 8. if w = “WHERE” then CALL SEARCH-CONDITION w = SCANNER(); 9. if w = “ORDER” then w = SCANNER(); \\ w = “BY” w = SCANNER(); \\w = column-name <= create a node v for select-statement <= make w a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make w a child of v <= make w a child of v

34 select-statement ::= SELECT [DISTINCT] select-list FROM table-list
[WHERE search-condition] [ORDER BY column-name] SELECT FROM WHERE From SELECT-LIST From TABLE-LIST From SEARCH-CONDITION SELECT-STMT 1. w = SCANNER(); \\ w = “SELECT” 2. w = SCANNER(); 3. if w = “DISTINCT” then w = SCANNER(); 4. CALL SELECT-LIST; 5. w = SCANNER(); \\ w = “FROM” 6. CALL TABLE-LIST; 7. w = SCANNER(); 8. if w = “WHERE” then CALL SEARCH-CONDITION w = SCANNER(); 9. if w = “ORDER” then w = SCANNER(); \\ w = “BY” w = SCANNER(); \\w = column-name <= create a node v for select-statement <= make w a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make w a child of v <= make w a child of v

35 select-statement ::= SELECT [DISTINCT] select-list FROM table-list
[WHERE search-condition] [ORDER BY column-name] SELECT FROM WHERE From SELECT-LIST From TABLE-LIST From SEARCH-CONDITION SELECT-STMT 1. w = SCANNER(); \\ w = “SELECT” 2. w = SCANNER(); 3. if w = “DISTINCT” then w = SCANNER(); 4. CALL SELECT-LIST; 5. w = SCANNER(); \\ w = “FROM” 6. CALL TABLE-LIST; 7. w = SCANNER(); 8. if w = “WHERE” then CALL SEARCH-CONDITION w = SCANNER(); 9. if w = “ORDER” then w = SCANNER(); \\ w = “BY” w = SCANNER(); \\w = column-name <= create a node v for select-statement <= make w a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make w a child of v <= make w a child of v

36 select-statement ::= SELECT [DISTINCT] select-list FROM table-list
[WHERE search-condition] [ORDER BY column-name] SELECT FROM WHERE From SELECT-LIST From TABLE-LIST From SEARCH-CONDITION SELECT-STMT 1. w = SCANNER(); \\ w = “SELECT” 2. w = SCANNER(); 3. if w = “DISTINCT” then w = SCANNER(); 4. CALL SELECT-LIST; 5. w = SCANNER(); \\ w = “FROM” 6. CALL TABLE-LIST; 7. w = SCANNER(); 8. if w = “WHERE” then CALL SEARCH-CONDITION w = SCANNER(); 9. if w = “ORDER” then w = SCANNER(); \\ w = “BY” w = SCANNER(); \\w = column-name <= create a node v for select-statement <= make w a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make w a child of v <= make w a child of v

37 select-statement ::= SELECT [DISTINCT] select-list FROM table-list
[WHERE search-condition] [ORDER BY column-name] SELECT FROM WHERE From SELECT-LIST From TABLE-LIST From SEARCH-CONDITION SELECT-STMT 1. w = SCANNER(); \\ w = “SELECT” 2. w = SCANNER(); 3. if w = “DISTINCT” then w = SCANNER(); 4. CALL SELECT-LIST; 5. w = SCANNER(); \\ w = “FROM” 6. CALL TABLE-LIST; 7. w = SCANNER(); 8. if w = “WHERE” then CALL SEARCH-CONDITION w = SCANNER(); 9. if w = “ORDER” then w = SCANNER(); \\ w = “BY” w = SCANNER(); \\w = column-name <= create a node v for select-statement <= make w a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make w a child of v <= make w a child of v

38 select-statement ::= SELECT [DISTINCT] select-list FROM table-list
[WHERE search-condition] [ORDER BY column-name] SELECT FROM WHERE From SELECT-LIST From TABLE-LIST From SEARCH-CONDITION SELECT-STMT 1. w = SCANNER(); \\ w = “SELECT” 2. w = SCANNER(); 3. if w = “DISTINCT” then w = SCANNER(); 4. CALL SELECT-LIST; 5. w = SCANNER(); \\ w = “FROM” 6. CALL TABLE-LIST; 7. w = SCANNER(); 8. if w = “WHERE” then CALL SEARCH-CONDITION w = SCANNER(); 9. if w = “ORDER” then w = SCANNER(); \\ w = “BY” w = SCANNER(); \\w = column-name <= create a node v for select-statement <= make w a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make w a child of v <= make w a child of v

39 select-statement ::= SELECT [DISTINCT] select-list FROM table-list
[WHERE search-condition] [ORDER BY column-name] SELECT FROM WHERE From SELECT-LIST From TABLE-LIST From SEARCH-CONDITION SELECT-STMT 1. w = SCANNER(); \\ w = “SELECT” 2. w = SCANNER(); 3. if w = “DISTINCT” then w = SCANNER(); 4. CALL SELECT-LIST; 5. w = SCANNER(); \\ w = “FROM” 6. CALL TABLE-LIST; 7. w = SCANNER(); 8. if w = “WHERE” then CALL SEARCH-CONDITION w = SCANNER(); 9. if w = “ORDER” then w = SCANNER(); \\ w = “BY” w = SCANNER(); \\w = column-name <= create a node v for select-statement <= make w a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make the result a child of v <= make w a child of v <= make w a child of v <= make w a child of v

40 What Does DBMS Do? Prepare a collection A of efficient algorithms for operations in relational algebra; For a given database program P: 1. understand the program P; Break the program P into “words” (lexical analysis); Use the language grammar to “parse” the program P; Make a parse tree for the program P.

41 Convert the input SQL program P into a parse tree
What Does DBMS Do? Prepare a collection A 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 A; take care of issues in optimization, consistency, and security. Convert the input SQL program P into a parse tree

42 Convert the input SQL program P into a parse tree
What Does DBMS Do? Prepare a collection A 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 A; take care of issues in optimization, consistency, and security. Convert the input SQL program P into a parse tree Lexical scanner: write a regular expression based on the lexical rules, convert it into a finite state automaton, and implement the automaton. Parse tree construction: for each nonterminal x, write a subroutine that constructs a parse tree with a root labeled with x: Given a syntax rule x ::= y1 y2 … yh: for each yk, if yk is a terminal, make yk the kth child of x; if yk is a nonterminal, recursively construct the parse tree Tk for yk, and let the root of Tk be the kth child of x.

43 What Does DBMS Do? Prepare a collection A 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 A; take care of issues in optimization, consistency, and security.


Download ppt "CPSC-608 Database Systems"

Similar presentations


Ads by Google