Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Query Compiler Parsing and Preprocessing. Meghna Jain(205)

Similar presentations


Presentation on theme: "The Query Compiler Parsing and Preprocessing. Meghna Jain(205)"— Presentation transcript:

1 The Query Compiler. 16. 1 Parsing and Preprocessing. Meghna Jain(205)
The Query Compiler Parsing and Preprocessing Meghna Jain(205) Dr. T. Y. Lin

2 Presentation Outline 16.1 Parsing and Preprocessing
Syntax Analysis and Parse Tree A Grammar for Simple Subset of SQL The Preprocessor Processing Queries Involving Views

3 Query compilation is divided into three steps
1. Parsing: Parse SQL query into parser tree. 2. Logical query plan: Transforms parse tree into expression tree of relational algebra. 3.Physical query plan: Transforms logical query plan into physical query plan. . Operation performed . Order of operation . Algorithm used . The way in which stored data is obtained and passed from one operation to another.

4 Form a query to a logical query plan
Parser Preprocessor Logical Query plan generator Query rewrite Preferred logical query plan Form a query to a logical query plan

5 Syntax Analysis and Parse Tree
Parser takes the sql query and convert it to parse tree. Nodes of parse tree: 1. Atoms: known as Lexical elements such as key words, constants, parentheses, operators, and other schema elements. 2. Syntactic categories: Subparts that plays a similar role in a query as <Query> , <Condition>

6 Grammar for Simple Subset of SQL
<Query> ::= <SFW> <Query> ::= (<Query>)‏ <SFW> ::= SELECT <SelList> FROM <FromList> WHERE <Condition> <SelList> ::= <Attribute>,<SelList> <SelList> ::= <Attribute> <FromList> ::= <Relation>, <FromList> <FromList> ::= <Relation> <Condition> ::= <Condition> AND <Condition> <Condition> ::= <Tuple> IN <Query> <Condition> ::= <Attribute> = <Attribute> <Condition> ::= <Attribute> LIKE <Pattern> <Tuple> ::= <Attribute> Atoms(constants), <syntactic categories>(variable), ::= (can be expressed/defined as)‏

7 Query and Parse T ree StarsIn(title,year,starName)
MovieStar(name,address,gender,birthdate)‏ Query: Give titles of movies that have at least one star born in 1960 SELECT title FROM StarsIn WHERE starName IN ( SELECT name FROM MovieStar WHERE birthdate LIKE '%1960%' );

8

9 Another query equivalent
SELECT title FROM StarsIn, MovieStar WHERE starName = name AND birthdate LIKE '%1960%' ;

10 Parse Tree <Query> <SFW>
SELECT <SelList> FROM <FromList> WHERE <Condition> <Attribute> <RelName> , <FromList> AND title StarsIn <RelName> MovieStar <Query> <Condition> <Condition> <Attribute> = <Attribute> <Attribute> LIKE <Pattern> starName name birthdate ‘%1960’

11 The Preprocessor Functions of Preprocessor
. If a relation used in the query is virtual view then each use of this relation in the form-list must replace by parser tree that describe the view. . It is also responsible for semantic checking 1. Checks relation uses : Every relation mentioned in FROM- clause must be a relation or a view in current schema. 2. Check and resolve attribute uses: Every attribute mentioned in SELECT or WHERE clause must be an attribute of same relation in the current scope. 3. Check types: All attributes must be of a type appropriate to their uses.

12 StarsIn(title,year,starName)
MovieStar(name,address,gender,birthdate)‏ Query: Give titles of movies that have at least one star born in 1960 SELECT title FROM StarsIn WHERE starName IN ( SELECT name FROM MovieStar WHERE birthdate LIKE '%1960%' );

13 Preprocessing Queries Involving Views
When an operand in a query is a virtual view, the preprocessor needs to replace the operand by a piece of parse tree that represents how the view is constructed from base table. Base Table: Movies( title, year, length, genre, studioname, producerC#)‏ View definition : CREATE VIEW ParamountMovies AS SELECT title, year FROM movies WHERE studioName = 'Paramount'; Example based on view: SELECT title FROM ParamountMovies WHERE year = 1979;

14 Thank You


Download ppt "The Query Compiler Parsing and Preprocessing. Meghna Jain(205)"

Similar presentations


Ads by Google