CPSC-608 Database Systems

Slides:



Advertisements
Similar presentations
CS 540 Database Management Systems
Advertisements

Midterm Review Lecture 14b. 14 Lectures So Far 1.Introduction 2.The Relational Model 3.Disks and Files 4.Relational Algebra 5.File Org, Indexes 6.Relational.
CPSC-608 Database Systems Fall 2009 Instructor: Jianer Chen Office: HRBB 309B Phone: Notes #2.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #10.
CPSC-608 Database Systems Fall 2010 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #9.
CPSC-608 Database Systems Fall 2010 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #4.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #7.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #6.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #4.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #11.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #3.
CPSC-608 Database Systems Fall 2008 Instructor: Jianer Chen Office: HRBB 309B Phone: Notes #4.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #13.
CPSC-608 Database Systems Fall 2010 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #5.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #9.
CPSC-608 Database Systems Fall 2008 Instructor: Jianer Chen Office: HRBB 309B Phone: Notes #3.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #12.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #14.
CPSC-608 Database Systems Fall 2010 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes 1.
CPSC-608 Database Systems Fall 2010 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #6.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes 1.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #2.
Constraints on Relations Foreign Keys Local and Global Constraints Triggers Following lecture slides are modified from Jeff Ullman’s slides
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #6.
CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #8.
CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #5.
CPSC-310 Database Systems
Scholastic Dishonesty
CPSC-310 Database Systems
CPSC-310 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
Introduction What is a Database?.
CPSC-310 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-310 Database Systems
CPSC-310 Database Systems
CPSC-310 Database Systems
CPSC-310 Database Systems
Query Processing B.Ramamurthy Chapter 12 11/27/2018 B.Ramamurthy.
SQL: The Query Language Part 1
SQL Fundamentals in Three Hours
Instructor 彭智勇 武汉大学软件工程国家重点实验室 电话:
Contents Preface I Introduction Lesson Objectives I-2
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
Scholastic Dishonesty
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
CPSC-608 Database Systems
Query Processing.
CPSC-608 Database Systems
CPSC-608 Database Systems
Presentation transcript:

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

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

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.

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);

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.

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 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

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

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

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

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

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 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

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;

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 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?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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.

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

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.

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. √