SlideShare a Scribd company logo
1 of 16
Download to read offline
Query Processing and
Optimization
Introduction
• In this chapter we shall discuss the techniques
used by a DBMS to process, optimize and execute
high-level queries.
• The techniques used to split complex queries into
multiple simple operations and methods of
implementing these low-level operations.
• The query optimization techniques are used to
chose an efficient execution plan that will
minimize the runtime as well as many other types
of resources such as number of disk I/O, CPU
time and so on.
Query Processing
• Query Processing is a procedure of transforming a high-level
query (such as SQL) into a correct and efficient execution plan
expressed in low-level language.
• When a database system receives a query for update or
retrieval of information, it goes through a series of
compilation steps, called execution plan.
• Query processing goes through various phases:
• first phase is called syntax checking phase, the system parses
the query and checks that it follows the syntax rules or not.
• It then matches the objects in the query syntax with the view
tables and columns listed in the system table.
• In second phase the SQL query is translated in to an algebraic
expression using various rules.
• So that the process of transforming a high-level SQL query into a
relational algebraic form is called Query Decomposition.
• The relational algebraic expression now passes to the query
optimizer.
• In third phase optimization is performed by substituting equivalent
expression depends on the factors such that the existence of
certain database structures, whether or not a given file is stored,
the presence of different indexes & so on.
• Query optimization module work in tandem with the join manager
module to improve the order in which joins are performed.
• At this stage the cost model and several other
estimation formulas are used to rewrite the query.
• The modified query is written to utilize system
resources so as to bring the optimal performance.
• The query optimizer then generates an action plan also
called a execution plan.
• This action plans are converted into a query codes that
are finally executed by a run time database processor.
• The run time database processor estimate the cost of
each action plan and chose the optimal one for the
execution.
Query Analyzer
• The syntax analyzer takes the query from the
users, parses it into tokens and analyses the
tokens and their order to make sure they
follow the rules of the language grammar.
• Is an error is found in the query submitted by
the user, it is rejected and an error code
together with an explanation of why the query
was rejected is return to the user.
Query Decomposition
• In query decomposition the query processing aims are to transfer
the high-level query into a relational algebra query and to check
whether that query is syntactically and semantically correct.
• Thus the query decomposition is start with a high-level query and
transform into query graph of low-level operations, which satisfy
the query.
• The SQL query is decomposed into query blocks (low-level
operations), which form the basic unit.
• Hence nested queries within a query are identified as separate
query blocks.
• The query decomposer goes through five stages of processing for
decomposition into low-level operation and translation into
algebraic expressions.
Query Analysis
• During the query analysis phase, the query is
syntactically analyzed using the programming
language compiler (parser).
• A syntactically legal query is then validated,
using the system catalog, to ensure that all
data objects (relations and attributes) referred
to by the query are defined in the database.
• The type specification of the query qualifiers
and result is also checked at this stage.
• Example:
SELECT emp_nm FROM EMPLOYEE WHERE
emp_desg>100
This query will be rejected because the comparison
“>100” is incompatible with the data type of
emp_desg which is a variable character string.
• At the end of query analysis phase, the high-level query
(SQL) is transformed into some internal representation
that is more suitable for processing.
• This internal representation is typically a kind of query
tree.
• A Query Tree is a tree data structure that
corresponds expression.
• A Query Tree is also called a relational algebra
tree.
– Leaf node of the tree, representing the base
input relations of the query.
– Internal nodes result of applying an operation in
the algebra.
– Root of the tree representing a result of the query.
• SELECT (P.proj_no, P.dept_no, E.name, E.add,
E.dob)
• FROM PROJECT P, DEPARTMENT D, EMPLOYEE
E
• WHERE P.dept_no = D.d_no AND D.mgr_id =
E.emp_id AND P.proj_loc = ‘Mumbai’ ;
• The three relations PROJECT, DEPARTMENT,
EMPLOYEE are represent as a leaf nodes P, D
and E, while the relational algebra operations
of the represented by internal tree nodes.
• Same SQL query can have man different
relational algebra expressions and hence
many different query trees.
• The query parser typically generates a
standard initial (canonical) query tree.
Query Normalization
• The primary phase of the normalization is to avoid
redundancy.
• The normalization phase converts the query into a
normalized form that can be more easily manipulated.
• In the normalization phase, a set of equivalency rules
are applied so that the projection and selection
operations included on the query are simplified to
avoid redundancy.
• The projection operation corresponds to the SELECT
clause of SQL query and the selection operation
correspond to the predicate found in WHERE clause.
• The equivalency transformation rules that are applied.
Semantic Analyzer
• The objective of this phase of query processing is to reduce the number of
predicates.
• The semantic analyzer rejects the normalized queries that are incorrectly
formulated.
• A query is incorrectly formulated if components do not contribute to the
generation of result.
• This happens in case of missing join specification.
• A query is contradictory if its predicate cannot satisfy by any tuple in the relation.
• The semantic analyzer examine the relational calculus query (SQL) to make sure it
contains only data objects that is table, columns, views, indexes that are defined in
the database catalog.
• It makes sure that each object in the query is referenced correctly according to its
data type.
• In case of missing join specifications the components do not contribute to the
generation of the results, and thus, a query may be incorrect formulated.

More Related Content

What's hot (20)

Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.
 
Query processing and Query Optimization
Query processing and Query OptimizationQuery processing and Query Optimization
Query processing and Query Optimization
 
Relational model
Relational modelRelational model
Relational model
 
Triggers
TriggersTriggers
Triggers
 
Nested queries in database
Nested queries in databaseNested queries in database
Nested queries in database
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
 
Query processing
Query processingQuery processing
Query processing
 
6. Integrity and Security in DBMS
6. Integrity and Security in DBMS6. Integrity and Security in DBMS
6. Integrity and Security in DBMS
 
Concurrency Control Techniques
Concurrency Control TechniquesConcurrency Control Techniques
Concurrency Control Techniques
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Query optimization
Query optimizationQuery optimization
Query optimization
 
13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMS
 
Concurrency control
Concurrency  controlConcurrency  control
Concurrency control
 
joins in database
 joins in database joins in database
joins in database
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
17. Recovery System in DBMS
17. Recovery System in DBMS17. Recovery System in DBMS
17. Recovery System in DBMS
 
Automata theory - CFG and normal forms
Automata theory - CFG and normal formsAutomata theory - CFG and normal forms
Automata theory - CFG and normal forms
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
 

Similar to Query processing

LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptxLECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptxAthosBeatus
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptxShafii8
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cRonald Francisco Vargas Quesada
 
Overview of query evaluation
Overview of query evaluationOverview of query evaluation
Overview of query evaluationavniS
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL ServerRajesh Gunasundaram
 
UNIT3 DBMS.pptx operation nd management of data base
UNIT3 DBMS.pptx operation nd management of data baseUNIT3 DBMS.pptx operation nd management of data base
UNIT3 DBMS.pptx operation nd management of data baseshindhe1098cv
 
Query optimization and performance
Query optimization and performanceQuery optimization and performance
Query optimization and performancefika sweety
 
Query optimization and performance
Query optimization and performanceQuery optimization and performance
Query optimization and performancefika sweety
 
Database Terminology and DBLC.pptx
Database Terminology and DBLC.pptxDatabase Terminology and DBLC.pptx
Database Terminology and DBLC.pptxTop1064
 

Similar to Query processing (20)

LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptxLECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
 
Query optimization
Query optimizationQuery optimization
Query optimization
 
Measures of query cost
Measures of query costMeasures of query cost
Measures of query cost
 
Query optimization
Query optimizationQuery optimization
Query optimization
 
Statistics
StatisticsStatistics
Statistics
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12c
 
1 query processing
1 query processing1 query processing
1 query processing
 
1 query processing
1 query processing1 query processing
1 query processing
 
Overview of query evaluation
Overview of query evaluationOverview of query evaluation
Overview of query evaluation
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
 
Mc seminar
Mc seminarMc seminar
Mc seminar
 
UNIT3 DBMS.pptx operation nd management of data base
UNIT3 DBMS.pptx operation nd management of data baseUNIT3 DBMS.pptx operation nd management of data base
UNIT3 DBMS.pptx operation nd management of data base
 
Query optimization and performance
Query optimization and performanceQuery optimization and performance
Query optimization and performance
 
Query optimization and performance
Query optimization and performanceQuery optimization and performance
Query optimization and performance
 
module 1.pptx
module 1.pptxmodule 1.pptx
module 1.pptx
 
Distributed DBMS - Unit 6 - Query Processing
Distributed DBMS - Unit 6 - Query ProcessingDistributed DBMS - Unit 6 - Query Processing
Distributed DBMS - Unit 6 - Query Processing
 
Oracle query optimizer
Oracle query optimizerOracle query optimizer
Oracle query optimizer
 
Development Guideline
Development GuidelineDevelopment Guideline
Development Guideline
 
Database Terminology and DBLC.pptx
Database Terminology and DBLC.pptxDatabase Terminology and DBLC.pptx
Database Terminology and DBLC.pptx
 

More from Ravinder Kamboj

More from Ravinder Kamboj (13)

Data warehouse,data mining & Big Data
Data warehouse,data mining & Big DataData warehouse,data mining & Big Data
Data warehouse,data mining & Big Data
 
DDBMS
DDBMSDDBMS
DDBMS
 
Cost estimation for Query Optimization
Cost estimation for Query OptimizationCost estimation for Query Optimization
Cost estimation for Query Optimization
 
Normalization of Data Base
Normalization of Data BaseNormalization of Data Base
Normalization of Data Base
 
Architecture of dbms(lecture 3)
Architecture of dbms(lecture 3)Architecture of dbms(lecture 3)
Architecture of dbms(lecture 3)
 
Sql fundamentals
Sql fundamentalsSql fundamentals
Sql fundamentals
 
Lecture 1&2(rdbms-ii)
Lecture 1&2(rdbms-ii)Lecture 1&2(rdbms-ii)
Lecture 1&2(rdbms-ii)
 
Java script
Java scriptJava script
Java script
 
File Management
File ManagementFile Management
File Management
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
DHTML
DHTMLDHTML
DHTML
 
CSA lecture-1
CSA lecture-1CSA lecture-1
CSA lecture-1
 
Relational database management system (rdbms) i
Relational database management system (rdbms) iRelational database management system (rdbms) i
Relational database management system (rdbms) i
 

Recently uploaded

31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
How to create _name_search function in odoo 17
How to create _name_search function in odoo 17How to create _name_search function in odoo 17
How to create _name_search function in odoo 17Celine George
 
The role of Geography in climate education: science and active citizenship
The role of Geography in climate education: science and active citizenshipThe role of Geography in climate education: science and active citizenship
The role of Geography in climate education: science and active citizenshipKarl Donert
 
Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...
Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...
Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...DrVipulVKapoor
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
16. Discovery, function and commercial uses of different PGRS.pptx
16. Discovery, function and commercial uses of different PGRS.pptx16. Discovery, function and commercial uses of different PGRS.pptx
16. Discovery, function and commercial uses of different PGRS.pptxUmeshTimilsina1
 
Employablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxEmployablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxryandux83rd
 
Jason Potel In Media Res Media Component
Jason Potel In Media Res Media ComponentJason Potel In Media Res Media Component
Jason Potel In Media Res Media ComponentInMediaRes1
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Osopher
 
The Emergence of Legislative Behavior in the Colombian Congress
The Emergence of Legislative Behavior in the Colombian CongressThe Emergence of Legislative Behavior in the Colombian Congress
The Emergence of Legislative Behavior in the Colombian CongressMaria Paula Aroca
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfChristalin Nelson
 
An Overview of the Calendar App in Odoo 17 ERP
An Overview of the Calendar App in Odoo 17 ERPAn Overview of the Calendar App in Odoo 17 ERP
An Overview of the Calendar App in Odoo 17 ERPCeline George
 
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEPART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEMISSRITIMABIOLOGYEXP
 

Recently uploaded (20)

Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Israel Genealogy Research Assoc. April 2024 Database Release
Israel Genealogy Research Assoc. April 2024 Database ReleaseIsrael Genealogy Research Assoc. April 2024 Database Release
Israel Genealogy Research Assoc. April 2024 Database Release
 
How to create _name_search function in odoo 17
How to create _name_search function in odoo 17How to create _name_search function in odoo 17
How to create _name_search function in odoo 17
 
The role of Geography in climate education: science and active citizenship
The role of Geography in climate education: science and active citizenshipThe role of Geography in climate education: science and active citizenship
The role of Geography in climate education: science and active citizenship
 
Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...
Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...
Geoffrey Chaucer Works II UGC NET JRF TGT PGT MA PHD Entrance Exam II History...
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
16. Discovery, function and commercial uses of different PGRS.pptx
16. Discovery, function and commercial uses of different PGRS.pptx16. Discovery, function and commercial uses of different PGRS.pptx
16. Discovery, function and commercial uses of different PGRS.pptx
 
CARNAVAL COM MAGIA E EUFORIA _
CARNAVAL COM MAGIA E EUFORIA            _CARNAVAL COM MAGIA E EUFORIA            _
CARNAVAL COM MAGIA E EUFORIA _
 
Employablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxEmployablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptx
 
Jason Potel In Media Res Media Component
Jason Potel In Media Res Media ComponentJason Potel In Media Res Media Component
Jason Potel In Media Res Media Component
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
 
Teaching Critical AI Literacies - Maha Bali
Teaching Critical AI Literacies - Maha BaliTeaching Critical AI Literacies - Maha Bali
Teaching Critical AI Literacies - Maha Bali
 
The Emergence of Legislative Behavior in the Colombian Congress
The Emergence of Legislative Behavior in the Colombian CongressThe Emergence of Legislative Behavior in the Colombian Congress
The Emergence of Legislative Behavior in the Colombian Congress
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdf
 
An Overview of the Calendar App in Odoo 17 ERP
An Overview of the Calendar App in Odoo 17 ERPAn Overview of the Calendar App in Odoo 17 ERP
An Overview of the Calendar App in Odoo 17 ERP
 
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEPART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
 

Query processing

  • 2. Introduction • In this chapter we shall discuss the techniques used by a DBMS to process, optimize and execute high-level queries. • The techniques used to split complex queries into multiple simple operations and methods of implementing these low-level operations. • The query optimization techniques are used to chose an efficient execution plan that will minimize the runtime as well as many other types of resources such as number of disk I/O, CPU time and so on.
  • 3. Query Processing • Query Processing is a procedure of transforming a high-level query (such as SQL) into a correct and efficient execution plan expressed in low-level language. • When a database system receives a query for update or retrieval of information, it goes through a series of compilation steps, called execution plan. • Query processing goes through various phases: • first phase is called syntax checking phase, the system parses the query and checks that it follows the syntax rules or not. • It then matches the objects in the query syntax with the view tables and columns listed in the system table.
  • 4. • In second phase the SQL query is translated in to an algebraic expression using various rules. • So that the process of transforming a high-level SQL query into a relational algebraic form is called Query Decomposition. • The relational algebraic expression now passes to the query optimizer. • In third phase optimization is performed by substituting equivalent expression depends on the factors such that the existence of certain database structures, whether or not a given file is stored, the presence of different indexes & so on. • Query optimization module work in tandem with the join manager module to improve the order in which joins are performed.
  • 5. • At this stage the cost model and several other estimation formulas are used to rewrite the query. • The modified query is written to utilize system resources so as to bring the optimal performance. • The query optimizer then generates an action plan also called a execution plan. • This action plans are converted into a query codes that are finally executed by a run time database processor. • The run time database processor estimate the cost of each action plan and chose the optimal one for the execution.
  • 6. Query Analyzer • The syntax analyzer takes the query from the users, parses it into tokens and analyses the tokens and their order to make sure they follow the rules of the language grammar. • Is an error is found in the query submitted by the user, it is rejected and an error code together with an explanation of why the query was rejected is return to the user.
  • 7. Query Decomposition • In query decomposition the query processing aims are to transfer the high-level query into a relational algebra query and to check whether that query is syntactically and semantically correct. • Thus the query decomposition is start with a high-level query and transform into query graph of low-level operations, which satisfy the query. • The SQL query is decomposed into query blocks (low-level operations), which form the basic unit. • Hence nested queries within a query are identified as separate query blocks. • The query decomposer goes through five stages of processing for decomposition into low-level operation and translation into algebraic expressions.
  • 8.
  • 9. Query Analysis • During the query analysis phase, the query is syntactically analyzed using the programming language compiler (parser). • A syntactically legal query is then validated, using the system catalog, to ensure that all data objects (relations and attributes) referred to by the query are defined in the database. • The type specification of the query qualifiers and result is also checked at this stage.
  • 10. • Example: SELECT emp_nm FROM EMPLOYEE WHERE emp_desg>100 This query will be rejected because the comparison “>100” is incompatible with the data type of emp_desg which is a variable character string. • At the end of query analysis phase, the high-level query (SQL) is transformed into some internal representation that is more suitable for processing. • This internal representation is typically a kind of query tree.
  • 11. • A Query Tree is a tree data structure that corresponds expression. • A Query Tree is also called a relational algebra tree. – Leaf node of the tree, representing the base input relations of the query. – Internal nodes result of applying an operation in the algebra. – Root of the tree representing a result of the query.
  • 12. • SELECT (P.proj_no, P.dept_no, E.name, E.add, E.dob) • FROM PROJECT P, DEPARTMENT D, EMPLOYEE E • WHERE P.dept_no = D.d_no AND D.mgr_id = E.emp_id AND P.proj_loc = ‘Mumbai’ ;
  • 13.
  • 14. • The three relations PROJECT, DEPARTMENT, EMPLOYEE are represent as a leaf nodes P, D and E, while the relational algebra operations of the represented by internal tree nodes. • Same SQL query can have man different relational algebra expressions and hence many different query trees. • The query parser typically generates a standard initial (canonical) query tree.
  • 15. Query Normalization • The primary phase of the normalization is to avoid redundancy. • The normalization phase converts the query into a normalized form that can be more easily manipulated. • In the normalization phase, a set of equivalency rules are applied so that the projection and selection operations included on the query are simplified to avoid redundancy. • The projection operation corresponds to the SELECT clause of SQL query and the selection operation correspond to the predicate found in WHERE clause. • The equivalency transformation rules that are applied.
  • 16. Semantic Analyzer • The objective of this phase of query processing is to reduce the number of predicates. • The semantic analyzer rejects the normalized queries that are incorrectly formulated. • A query is incorrectly formulated if components do not contribute to the generation of result. • This happens in case of missing join specification. • A query is contradictory if its predicate cannot satisfy by any tuple in the relation. • The semantic analyzer examine the relational calculus query (SQL) to make sure it contains only data objects that is table, columns, views, indexes that are defined in the database catalog. • It makes sure that each object in the query is referenced correctly according to its data type. • In case of missing join specifications the components do not contribute to the generation of the results, and thus, a query may be incorrect formulated.